Search code examples
javascriptfootable

How to retrieve column data from Footable


We have a Footable in our page with some data, and one column has a delete row button, working as expected.

Problem is, when deleterow is pressed, we want to retrieve from the column a value, to do some process with it.

Example:

ID -- Name -- Delete
--------------------
01 -- John -- Delete
02 -- Doe  -- Delete

When I press delete on second row, I want to retrieve this value, to search on an array, and delete it from there too, and to pass as parameter to an Ajax call.

I readed something like data-value but don't know how to get it. On delete row, there is a code like this:

$('table').footable().on('click', '.row-delete', function(e) {
    e.preventDefault();
    //get the footable object
    var footable = $('table').data('footable');

    //get the row we are wanting to delete
    var row = $(this).parents('tr:first');

    //delete the row
    footable.removeRow(row);
});

I know row has the data, but don't know/understand how to extract the column I need.

Regards and thanks.


Solution

  • You can get at the columns in the TR as TD elements eg

    var columns = $('td',row); // all the TD elements in the row
    

    You can get at individual columns by index (0-based) eg

    var someColumn = $('td',row)[1];
    

    Or if the column you are intersted in has a class eg:

    var someColumn = $('td.someclass',row);