Bug Fix/Feature Request - Less predictable field ID attributes

Bug Fix/Feature Request - Less predictable field ID attributes

gurueviguruevi Posts: 3Questions: 1Answers: 0

DataTables and DataTables Editor makes predictable and duplicate field/row ID attributes (eg. DTE_Field_tags or row_1). This is a problem if multiple tables have the same field names and they are both present (or open) or you query the ID through DataTables() object, both will return the same ID but selecting them only selects the "last one".

Select2 for example binds to the DOM based on this ID (using DataTables.Editor.safeId) and thus multiple tables on the same page with the same field names (eg. multiple tables with "tags" fields) cause Select2 and other plugins to misbehave. I'm working to have multiple editors open (not in modals) on the page at the same time which causes similar problems with programmatically selecting the 'right' field (it only selects the last used one)

One solution is to pass unique ID's for each field by passing a string in the "id" field as part of the object but it would be 'better/easier' if either the safeId function or all such generators would produce ids based on the table ID (eg. myTable_row_1 instead of just row_1).

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Hi,

    You could use the fields.className option to add an additional class to the field container element which allows finer controlled CSS selection.

    It would also be possible to use the open and close events in combination with displayNode() to add a class to the Editor display for a specific Editor - e.g.:

    editor1.on( 'open', function () {
      $( editor1.displayNode() ).addClass( 'editor1' );
    } );
    
    editor1.on( 'close', function () {
      $( editor1.displayNode() ).removeClass( 'editor1' );
    } );
    

    Regards,
    Allan

This discussion has been closed.