Individual Column Filtering for Dynamically Generated Table
Individual Column Filtering for Dynamically Generated Table
Hi! (First, I'm a first time forum poster so I'd like to say Thank You! for building DataTables.)
I can't figure out how to get Individual Column Filtering working for my Dynamically Generated Table. I'm trying to combine these two examples:
http://www.datatables.net/examples/api/multi_filter.html
http://www.datatables.net/examples/data_sources/server_side.html
My form initializes correctly, and the main search box (sSearch) works. But I can't get the other search inputs to filter. What am I doing wrong? Thanks in advance for any help.
(For the sake of getting things off the ground, I've keep a lot of the code (input names, etc) the same as the examples and I will change them once I get things to work.)
Footer of my table:
JavaScript:
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/crm/datatables/server_processing.php",
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
newclass = aData[4].replace(" ","");
$(nRow).addClass(newclass);
return nRow;
}
} );
var oTable = $('#example').dataTable( {
"oLanguage": {
"sSearch": "Search all columns:"
}
} );
$("tfoot input").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilter( this.value, $("tfoot input").index(this) );
} );
} );
I can't figure out how to get Individual Column Filtering working for my Dynamically Generated Table. I'm trying to combine these two examples:
http://www.datatables.net/examples/api/multi_filter.html
http://www.datatables.net/examples/data_sources/server_side.html
My form initializes correctly, and the main search box (sSearch) works. But I can't get the other search inputs to filter. What am I doing wrong? Thanks in advance for any help.
(For the sake of getting things off the ground, I've keep a lot of the code (input names, etc) the same as the examples and I will change them once I get things to work.)
Footer of my table:
JavaScript:
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/crm/datatables/server_processing.php",
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
newclass = aData[4].replace(" ","");
$(nRow).addClass(newclass);
return nRow;
}
} );
var oTable = $('#example').dataTable( {
"oLanguage": {
"sSearch": "Search all columns:"
}
} );
$("tfoot input").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilter( this.value, $("tfoot input").index(this) );
} );
} );
This discussion has been closed.
Replies
Oh - and you are initialising the table twice (does it not give you an error for that?!). Just more oLanguage into your first init object.
Allan
I am using MySQL and PHP so that shouldn't be the problem. Is there anything in my code (other than initializing twice) that is wrong?
As for initializing twice, it does not give me an error.
Allan
It works in Firefox and Chrome for me. Not in IE or Safari.
On a different note, the weird formatting you see below the DataTable is my in-process attempt to access all the data sent from the server (there are 18 hidden columns in the table) but I am having trouble accessing the data in the hidden columns.
For the hidden data - are you using fnGetData - you can't access the hidden columns using DOM methods since they are removed from the DOM.
Allan
Not having quotes around "class" was the problem for IE as well!
I was trying to use fnGetData but THEN was running into the problem of re-initializing.