Storing context to easily process select change listener

Storing context to easily process select change listener

fastcarsfastcars Posts: 1Questions: 1Answers: 0

I am using one of the most recent versions of datatables and have multiple tables with the same structure on a page.

I have a column renderer that renders a select with some hundreds of options.
I can add a change listener to this column no problems. but when I am called back in the change listener I want to put the data back into the underlying datatable row/cell.

I dont really want to use globals and track the last clicked button to determine which datatable the select belongs to, the preference is to at time of adding the row, to store the datatable into the generated "tr" after calling datatable.row.add(...)

How do I get the tr from the datatables row that has just been added?
I call draw() after add so I assume the dom has been created...
Or is there a better way to do this?

$(document).on('change', '.iso',function() {
var row = $(this).closest('tr')[0];
// which of four data tables does this event belong to?
});

Answers

  • kthorngrenkthorngren Posts: 14,616Questions: 25Answers: 3,469

    Maybe something like this will work:

    $(document).on('change', '.iso',function() {
      var row = $(this).closest('tr')[0];
      var table = $(this).closest('table').DataTable();
    });
    

    Kevin

Sign In or Register to comment.