afnFiltering is called for both tables, but I need it just for one table.

afnFiltering is called for both tables, but I need it just for one table.

afarberafarber Posts: 53Questions: 0Answers: 0
edited June 2012 in General
Hello,

I use CDN 1.9.1 to display 2 tables at the pages like this one:

http://preferans.de/user.php?id=OK344792675095
http://debug.datatables.net/olarik

On the top of one table I have 3 checkboxes which I use
to filter rows displayed in one of the tables:

[code]
$.fn.dataTableExt.afnFiltering.push(
function(oSettings, aData, iDataIndex) {
// HACK: do not call for comments table
if (aData.length != 33)
return true;

//console.dir(aData);
var bid = [ aData[3], aData[13], aData[23] ];
var misere = ($.inArray('Misere', bid) > -1);
var pass = ('Pass' == bid[0] && 'Pass' == bid[1] && 'Pass' == bid[2]);

if (misere)
return $('#misere_box').is(':checked');

if (pass)
return $('#pass_box').is(':checked');

return $('#usual_box').is(':checked');
}
);
[/code]

Everything works ok, but once I have added console.dir(aData)
and have noticed that the function is called for both tables!

So I've added a check for the number of columns (since
one table has 3 and the other one has 33 columns) - see above.

My question is if there is a better way to specify the afnFiltering
function for just one table (since I'm going to add some
checkboxes for the other table too).

Thank you
Alex

Replies

  • afarberafarber Posts: 53Questions: 0Answers: 0
    edited June 2012
    (corrected typo)
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    This I'm afraid is a limitation in DataTables - one that I will be looking to address in v1.11 by my current roadmap.

    The way I tend to do it, is an if condition much like you have, but check on the TABLE node, rather than the number of records. oSettings.nTable is the TABLE node.

    Allan
  • afarberafarber Posts: 53Questions: 0Answers: 0
    edited June 2012
    Thank you Allan, I've changed my code to the more readable:

    [code]
    // do not call for comments table
    if ('comments_table' == oSettings.nTable.id)
    return true;
    [/code]

    My further "nitpick" is that I can't use mDataProp in the afnFiltering function, maybe you plan to address that too? My current code has to use numeric offsets:

    [code]
    var bid = [ aData[3], aData[13], aData[23] ];
    var misere = ($.inArray('Misere', bid) > -1);
    [/code]

    Regards
    Alex
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Interesting one that. I'm not sure how easily I can address that without breaking backwards compatibility. However, I have added it to my to-do list to check that out. Thanks for flagging that up.

    Allan
This discussion has been closed.