Accessing the table row during filtering with afnFiltering

Accessing the table row during filtering with afnFiltering

wellsoliverwellsoliver Posts: 2Questions: 0Answers: 0
edited June 2013 in General
Hey all. I'd like to be able to access the table row itself during filtering b/c I am trying to sort by some data that's not displayed in the columns, but stored as row-level attributes in the HTML, e.g. . You can't use the jQuery selector "table tbody tr:eq(N)" because the rows are hidden. Something like:

[code]
$.fn.dataTableExt.afnFiltering.push(
function(settings, data, i) {
var tablerow = $("table#id tbody tr:eq(" + i + ")");

if (tablerow.attr("attr1") != "foo") {
return false;
}

return true;
}
);
[/code]

But like I said that won't work. Is there another way? Thanks.

Replies

  • phloopyphloopy Posts: 5Questions: 0Answers: 0
    Use fnGetNodes, passing it the index of the row you want.

    [code]
    $.fn.dataTableExt.afnFiltering.push(
    function(settings, data, iDataIndex) {
    var oTable = $('#' + oSettings.sTableId).dataTable();
    var row = oTable.fnGetNodes(iDataIndex);
    return $(row).attr("attr1") == "foo";
    }
    );
    [/code]
  • phloopyphloopy Posts: 5Questions: 0Answers: 0
    My previous comment (which I can't edit) uses both 'settings' and 'oSettings' for the same variable. Make sure they agree on what to call themselves if you use the code :p
This discussion has been closed.