Filtering all tables in a mulitple tables per page setup
Filtering all tables in a mulitple tables per page setup
kristoffer
Posts: 4Questions: 1Answers: 0
I'm creating a site from the Multiple Tables example but i wan't to filter all the tables at once.
To do so, I have written a new API-function based on the fnFilter-function. The solution works but it can most probably be done in a more efficient manner. I'm posting my soluton here. Please be free to comment on my solution.
// Kristoffer
var oTable;
$.fn.dataTableExt.oApi.fnFilterAll = function(oSettings, sInput, iColumn, bEscapeRegex) {
var oSettings;
for (var i = 0; i < this.dataTableSettings.length; i++) {
oSettings = this.dataTableSettings[i];
// ** Just copied from the fnFilter function
if (typeof bEscapeRegex == 'undefined') {
bEscapeRegex = true;
}
if (typeof iColumn == "undefined" || iColumn === null) {
/* Global filter */
this.oApi._fnFilterComplete(oSettings, {
"sSearch": sInput,
"bEscapeRegex": bEscapeRegex
}, 1);
}
else {
/* Single column filter */
oSettings.aoPreSearchCols[iColumn].sSearch = sInput;
oSettings.aoPreSearchCols[iColumn].bEscapeRegex = bEscapeRegex;
this.oApi._fnFilterComplete(oSettings, oSettings.oPreviousSearch, 1);
}
// ** End of copy
}
}
$(document).ready(function() {
oTable = $(".dataTable").dataTable( {
"oLanguage": {
"sUrl": "js/dataTables-1.5/media/sv_SE.txt"
}
});
$("#search").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilterAll(this.value);
} );
});
To do so, I have written a new API-function based on the fnFilter-function. The solution works but it can most probably be done in a more efficient manner. I'm posting my soluton here. Please be free to comment on my solution.
// Kristoffer
var oTable;
$.fn.dataTableExt.oApi.fnFilterAll = function(oSettings, sInput, iColumn, bEscapeRegex) {
var oSettings;
for (var i = 0; i < this.dataTableSettings.length; i++) {
oSettings = this.dataTableSettings[i];
// ** Just copied from the fnFilter function
if (typeof bEscapeRegex == 'undefined') {
bEscapeRegex = true;
}
if (typeof iColumn == "undefined" || iColumn === null) {
/* Global filter */
this.oApi._fnFilterComplete(oSettings, {
"sSearch": sInput,
"bEscapeRegex": bEscapeRegex
}, 1);
}
else {
/* Single column filter */
oSettings.aoPreSearchCols[iColumn].sSearch = sInput;
oSettings.aoPreSearchCols[iColumn].bEscapeRegex = bEscapeRegex;
this.oApi._fnFilterComplete(oSettings, oSettings.oPreviousSearch, 1);
}
// ** End of copy
}
}
$(document).ready(function() {
oTable = $(".dataTable").dataTable( {
"oLanguage": {
"sUrl": "js/dataTables-1.5/media/sv_SE.txt"
}
});
$("#search").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilterAll(this.value);
} );
});
This discussion has been closed.
Replies
Looks superb! Thanks very much for sharing that with everyone :-)
Do you mind if I put that on the DataTables plug-ins page? Do you have a link you would like me to put up for the credit?
Thanks
Allan
Thank you for a great plugin to jQuery.
// Kristoffer
That's fantastic - thanks very much! I've put your plug-in up here: http://datatables.net/plug-ins#api_fnFilterAll .
If you are willing to send over a Swedish translation as well - that would also be much appreciated!
Thanks,
Allan