Monday, November 20, 2017

Get row data from Datatables

You know how you'll have a action item on every row of your Datatable and need to get that row data when that item is clicked?



Here's how:

//
// create datatable
//
var table = $('#table').DataTable({
    ...
    ...
});

//
// handle clicks of the action selector
//
$('.action-selector').click(function(ev){
    var rowdata = table.row( $(this).parents('tr') ).data();
    //
    // rowdata now has the data from the row that 'action-selector' was clicked on
    //
}

No comments:

Post a Comment