prit4fun
prit4fun

Reputation: 460

Datatables show/hide columns disturbs column filtering

I'm trying to set up data tables with column filtering and show/hide functionality. It seems to work fine when the selection of columns is in ordered way like 0,1,2,3,4,5 but the Individual column filter mixes up with common search function when selecting columns in unordered way like 0,1,2,3,6. In this instance when column filter 6 is searched it behaves like a common search function.

On inspecting the requests in fire bug column filter 6 values are passed in sSearch instead of sSearch_6. Here is my code:

$(document).ready(function () {

  var table=  $("#data_table").dataTable({
        "bDestroy":true,
        "bStateSave": true,
        "aaSorting": [[1, "asc"]], 
        "bProcessing": false,
        "bServerSide": true,
        "sAjaxSource": "/queryDb",
        "bJQueryUI": true,
        "bAutoWidth": false,
        "bFilter":true,
        "bLengthChange": true,
        "bPaginate": true,
        "bSort": true,
        "iDisplayLength": 10,
        "bInfo": true,
        "sPaginationType": "full_numbers", 
        "fnDrawCallback" : function() {

    }

    }).columnFilter({
        sPlaceHolder: "head:after",
        aoColumns: [ { type: "text" },
                     { type: "text" },
                     { type: "text" },
                     { type: "text" },
                     { type: "text" },
                     { type: "text" },
                     { type: "text" },
                     { type: "text" },
                     { type: "text" },
                     { type: "text" }
                     ]
                     });
                     }); 

Functions for show/hide:

function fnShow(iCol)
{
    var oTable = $("#data_table").dataTable();
    var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
    oTable.fnSetColumnVis( iCol, true );
}
function fnHide(iCol2)
{
    var oTable2 = $("#data_table").dataTable();
    var bVis = oTable2.fnSettings().aoColumns[iCol2].bVisible;
    oTable2.fnSetColumnVis( iCol2, false );
}

Kindly help me in resolving this bug.

Upvotes: 0

Views: 1366

Answers (1)

prit4fun
prit4fun

Reputation: 460

Seems like column filter plugin is buggy. I removed column filter plugin and created custom search inputs for each column and appended those values in server side ajax request using fnFilter().

Like, table.fnFilter(""); table.fnFilter("val0",0); table.fnFilter("val1",1); and so.

Upvotes: 0

Related Questions