Using fnMultiFilter Plugin

Using fnMultiFilter Plugin

paopao Posts: 9Questions: 0Answers: 0
edited November 2013 in General
Hi,

I am just starting to use the datatables API for a new piece of work and I wanted to use multi column searching. I have ripped off the examples just to get me started and I cannot get the fnMultiFilter to work, the code I am using is exactly what is on the example page but it does not pass any parameters back to my servlet.

Here is my function taken from the example:

[code]
$.fn.dataTableExt.oApi.fnMultiFilter = function( oSettings, oData ) {
for ( var key in oData ) {

if ( oData.hasOwnProperty(key) ) {
for ( var i=0, iLen=oSettings.aoColumns.length ; i

Replies

  • paopao Posts: 9Questions: 0Answers: 0
    I thought I would post my entire html page as it is just a mock up and is quite small, hopefully someone will be able to see where I am going wrong as I am not getting any search parameters passed back:

    [code]

    <!DOCTYPE HTML>







    @import "http://datatables.net/release-datatables/media/css/demo_page.css";
    @import "http://datatables.net/release-datatables/media/css/demo_table.css";



    var asInitVals = new Array();
    var oTable;

    $.fn.dataTableExt.oApi.fnMultiFilter = function( oSettings, oData ) {
    for ( var key in oData ) {
    if ( oData.hasOwnProperty(key) ) {
    for (var i = 0, iLen = oSettings.aoColumns.length; i < iLen ; i++) {
    if( oSettings.aoColumns[i].sName == key ) {
    /* Add single column filter */
    oSettings.aoPreSearchCols[ i ].sSearch = oData[key];
    console.log(oData[key]);
    break;
    }
    }
    }
    }
    console.log(oSettings);
    this.oApi._fnReDraw( oSettings );
    };

    $(document).ready(function() {
    oTable = $('#example').dataTable( {
    "bProcessing": true,
    "sAjaxSource": './servlet/DataTables',
    "bServerSide": true,
    "sServerMethod": "POST",
    "bFilter": false, //hide the search box
    "aoColumns": [
    { "sName": "engine" },
    { "sName": "browser" },
    { "sName": "platform" },
    { "sName": "version" },
    { "sName": "grade" }
    ]
    } );

    $("thead input").keyup( function () {
    /* Filter on the column (the index) of this element */
    oTable.fnMultiFilter( { "engine": "Gecko", "browser": "Firefox", "platform": "Win" } );
    } );

    /*
    * Support functions to provide a little bit of 'user friendlyness' to the textboxes in
    * the footer
    */
    $("thead input").each( function (i) {
    asInitVals[i] = this.value;
    } );

    $("thead input").focus( function () {
    if ( this.className == "search_init" ) {
    this.className = "";
    this.value = "";
    }
    } );

    $("thead input").blur( function (i) {
    if ( this.value == "" ) {
    this.className = "search_init";
    this.value = asInitVals[$("thead input").index(this)];
    }
    });
    });














    Rendering engine
    Browser
    Platform(s)
    Engine version
    CSS grade











    [/code]
  • paopao Posts: 9Questions: 0Answers: 0
    ok did not realise at first that I needed to include a working example, obviously the ajax call will give you a 404 error but you can still see that the search parameters are not passed, or dont appear to be when looking at the request with firebug.

    http://live.datatables.net/erokol/2
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi!

    > "bFilter": false, //hide the search box

    Oops - that disabled the filtering entirely :-).

    If you want to keep filtering enabled, but hide just the search box, use the sDom option and remove the `f` . Other than that - it should work (does when I try it here: http://live.datatables.net/erokol/3/edit#preview ).

    Allan
  • paopao Posts: 9Questions: 0Answers: 0
    Hi Allan, thanks for the reply I feel like a complete dummy now!!

    had been using multiple forum posts and examples to try to build a mock up of the table I want to use in production!

    I had no idea that disabling that option would equal no filtering at all but its actually kind of obvious!!

    Cheers for the help, I will now look to remove the search field as per your suggestion.

    Paul
This discussion has been closed.