Filtering all tables in a mulitple tables per page setup

Filtering all tables in a mulitple tables per page setup

kristofferkristoffer Posts: 4Questions: 1Answers: 0
edited April 2009 in General
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);
} );
});

Replies

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin
    Hi kristoffer,

    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
  • kristofferkristoffer Posts: 4Questions: 1Answers: 0
    No of course not. I would be happy if it could help someone else. My homepage is http://www.kmmtiming.se so you can use that one as a credit-link. (The page is only in swedish right now). I have a swedish translation for DataTables as well that i can send to you.
    Thank you for a great plugin to jQuery.

    // Kristoffer
  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin
    Hi 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
This discussion has been closed.