Datatables - Search Box outside datatable

前端 未结 11 1347
攒了一身酷
攒了一身酷 2020-11-30 17:08

I\'m using DataTables (datatables.net) and I would like my search box to be outside of the table (for example in my header div).

Is this possible ?

11条回答
  •  一个人的身影
    2020-11-30 17:41

    I want to add one more thing to the @netbrain's answer relevant in case you use server-side processing (see serverSide option).

    Query throttling performed by default by datatables (see searchDelay option) does not apply to the .search() API call. You can get it back by using $.fn.dataTable.util.throttle() in the following way:

    var table = $('#myTable').DataTable();
    var search = $.fn.dataTable.util.throttle(
        function(val) {
            table.search(val).draw();
        },
        400  // Search delay in ms
    );
    
    $('#mySearchBox').keyup(function() {
        search(this.value);
    });
    

提交回复
热议问题