How to know the field name of the column on which the inline edit has been triggered?

How to know the field name of the column on which the inline edit has been triggered?

timothy.ctr.searcy@faa.govtimothy.ctr.searcy@faa.gov Posts: 6Questions: 4Answers: 0
edited June 19 in Editor

Hi,

I understand that I can edit only one field in an inline edit call. On the presubmit event, I am wanting to know which column, or field is being updated. I am trying to use modifier() but it gives me the complete object. I want to know how to derive the field name from it.

Some excerpts from my code:

$('#dataTable').on('click', 'tbody td.editable', function (e) {
            editor.inline(this, {
                submit: 'allIfChanged'
            });
        });
        
        editor.on('preSubmit', function (e, o, action) {
            
            console.table(editor.modifier());

            /* Is there any api like below code?
            //console.log(editor.modifier().fieldName());
            //console.log(editor.modifier().column());
             */
            
        });

Answers

  • colincolin Posts: 6,526Questions: 0Answers: 1,123

    Hi @timothy.ctr.searcy@faa.gov ,

    You can get the row that's being edited with ids(), but not the specific cell. There are two ways you could go though. You could either get the cell with the class DTE_Inline, or, you could make a note of the cell being edited in a variable in your click event, then reference that later in the preSubmit event.

    Not ideal, but hopefully they'll do the trick,

    Cheers,

    Colin

  • stolstol Posts: 16Questions: 2Answers: 1

    I have inline editing on a few columns, but I want a confirm box for only one of them.
    This is what I did based on colins idea:
    In the click event that activated the inline editing:

    var row = $(this).closest('tr');
                    var rowData = table.row(row).data();
                    rowId = rowData['DT_RowId'];
                    editor.inline( this, {
                        onBlur: 'submit'
                    } );
    

    Then in the presubmit function:

    editor.on('preSubmit', function (e, data, action) {
                    if (action == 'edit') {
                        var submitteddata = data.data[rowId];
                        var colname = '';
                        $.each(submitteddata, function (key, value) {
                            colname = key;
                        });
                        // console.log(colname);
                        if (colname == 'topicid') {
                            if(!confirm('Are you sure you want to change the topic?')) {
                                editor.close();
                                return false;
                            }
                        }
                        else return true;
                    }
    
                });
    
  • allanallan Posts: 50,737Questions: 1Answers: 7,581 Site admin

    displayed is the magic function you want here. It will give a list of the field names which are currently shown by the editing instance. In the case of inline editing, that's just the single one that is editable.

    Allan

Sign In or Register to comment.