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.
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
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
This discussion has been closed.
Replies
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
[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
Allan