Filtering Columns

Filtering Columns

NekkonNekkon Posts: 4Questions: 3Answers: 0
edited July 2014 in DataTables 1.10

Hello, i have this code below that initializes my table and filters the column aData[0] based on what is typed in a text input with id="test". Why doesn't it work? I redraw the table by clicking a button ( the code at the end ). Any suggestions? The last column has select that can be ordered by value. Other than the filtering everything else works fine..

$('#example').dataTable( {
"columns": [
null ,
null ,
null ,
null ,
null ,
null ,
null ,
null ,
{ "orderDataType": "dom-select" }
],paging:false
} );

$.fn.dataTableExt.afnFiltering.push(
    function (oSettings, aData, iDataIndex) {
        var $filterSelectedSelect = $('select[name="' + oSettings.sTableId + '_selectedFilter"]');
        if ($filterSelectedSelect.length == 0)
            return true; // feature not enabled

        if ($filterSelectedSelect.val() == 'All')
            return true; // all items selected


        var testindex=document.getElementById('test').value;
        var tableindex = aData[0];
        var isvalid;

    isvalid=false;
    if(testindex==tableindex){
        isvalid=true;
    }

        return isvalid;


    }
);

function tablerefresh(){
var oTable = $("#example").dataTable();
oTable.fnDraw();
}

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Looks like it should work - it will be quite slow since there is a lot of DOM reading going on on for every filter call, but the basic idea looks okay. Can you link us to the page so I can take a look and see what is going wrong?

    Allan

This discussion has been closed.