简体   繁体   中英

datatables filter in different input

I have a problem with datatables. I can't enable bFilter in input outside table container. There is a code which I initialize my datatable.

var table = $('#table-perms-users').DataTable( {
        "scrollY": tableHeight + "px",
        "scrollX": "100%",
        "scrollXInner": "100%",
        "bScrollCollapse": true,
        "bSort" : true,
        "bInfo": false,
        "bFilter": false,
        "bPaginate": false,
        "columns": [
            { "orderDataType": "dom-last-name"},
            { "orderDataType": "dom-checkbox" },
            { "orderDataType": "dom-checkbox" },
            { "orderDataType": "dom-checkbox" },
            { "orderDataType": "dom-checkbox" },
            { "orderDataType": "dom-checkbox" },
            { "orderDataType": "dom-checkbox" },
            { "orderDataType": "dom-checkbox" },
            { "orderDataType": "dom-checkbox" },
            { "orderDataType": "dom-checkbox" },
            { "orderDataType": "dom-checkbox" }
        ]
    } );

I try to enable filter with function fnFilter() on keyup event on input. It looks like that:

      $('#dTSearch').keyup(function(){
        table.fnFilter($(this).val());
      });

But I can see an error message on console:

Uncaught TypeError: undefined is not a function (index):10086(anonymous function)
(index):10086jQuery.event.dispatch jquery.1.11.1.js?t=1402046180:4641elemData.handle

Maybe someone can answer me what I doing wrong? Looks like it didn't see var table or didn't find function fnFilter. Maybe I have some mistakes in define my datatable?

I hope you are using Static mode of dataTables.

since you mentioned as "bFilter": false in the configuration of dataTable for you, probably does not allow you to filter.

if you make bFilter:true, it takes care of the filtering by default in static mode.

And check if fnFilter parameter value. for more info on fnFilter you can open dataTables.js file (lib) you associated.

All was more easy that i think. There end variant of code:

    $('#dTSearch').keyup(function()
    {
        table.columns(0).search($(this).val()).draw();
    });

UPD: bFilter option should be enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM