How to apply filter to specific datatable

后端 未结 6 1391
既然无缘
既然无缘 2020-12-08 21:03

Is it possible to apply a certain filter to only one datatable? I have the following filter function that I am applying on document ready, I don\'t know if this is proper pr

6条回答
  •  情话喂你
    2020-12-08 21:34

    Haven't tried, but how about something like this ?

    $.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {
            if ( oSettings.nTable == document.getElementById( 'productTable' )){
                var checked = $('#instock').is(':checked');
                var qntStock = 1; 
                var stockCol = 3; 
    
                if (!checked) {
                    return true;
                }
                if (checked && aData[stockCol] > qntStock) {
                    return true;
                }
    
                return false;
            }
    }
    );
    

    the idea came from this thread : 2 datatables & 2 filters on the same page


    You can also try out my yadcf plugin for datatable , here its showcase url, its has 9 different types of filters + additional API functions that can help you load table pre filtered or add single filter for filtering multiple table and many other cool stuff..

提交回复
热议问题