Selected row information when using Edit button to open Editor dialog?

Selected row information when using Edit button to open Editor dialog?

STScI WASABI TeamSTScI WASABI Team Posts: 6Questions: 3Answers: 0

Is it possible to get selected row information when you use the edit button to open the editor dialog? I would like to customize the title of the dialog with information from the row; currently I do this thru click handlers:

$('#the-table tbody').on( 'click', 'tr td.cell-being-clicked', function () {    
  var rowId = $(this).closest('tr').find(".the-row-id").html();

  editor
    .title( 'Edit ' + rowId + ' Values')
    .buttons( 'Update' )
    .edit( $(this).closest('tr') );
});

If I can get row information I can use the open event instead to set the title for all editor dialog calls.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin
    Answer ✓

    Yes - the ids() method can be used in combination with DataTables' row().data() method:

    editor.on( 'open', function () {
      var d = table.row( editor.ids(true) ).data();
      ...
    } );
    

    Regards,
    Allan

  • rf1234rf1234 Posts: 2,985Questions: 87Answers: 421
    edited November 2018 Answer ✓

    Here is a custom button for editing that you can customize whichever way you like. I customized the title but you can also customize the button label and other things.

    $.fn.dataTable.ext.buttons.yourSpecialEditButton = {
        extend: 'edit',
        name: "yourSpecialEditButton",
        action: function ( e, dt, button, config ) {
                var selected = dt.row( {selected: true} );
                var yourTitle;
                if (selected.any()) {
                    yourTitle = selected.data().yourField;
                    yourEditor
                      //  .title($.fn.dataTable.Editor.defaults.i18n.edit.title) //you can also use the Editor defaults
                        .title(yourTitle) //whatever title you like
                        .buttons({
                            label: $.fn.dataTable.Editor.defaults.i18n.edit.submit, //whatever button label you want
                            className: 'class of the color you like',
                            fn: function () {
                                this.submit();
                            }
                        })
                        .edit( yourEditor.rows().indexes() );
            }
        }
    };
    
    .......................
    
    buttons: [
                    "colvis",
                    "yourSpecialEditButton "
    ]
    
    

    Just saw Allan's reply: His suggestion is probably better provided you are using Editor 1.7.4 and newer which I don't. My solution also works with older Editor versions.

  • STScI WASABI TeamSTScI WASABI Team Posts: 6Questions: 3Answers: 0

    thanks for the custom button example!

This discussion has been closed.