Datatables - Search Box outside datatable

前端 未结 11 1345
攒了一身酷
攒了一身酷 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:47

    You can use the DataTables api to filter the table. So all you need is your own input field with a keyup event that triggers the filter function to DataTables. With css or jquery you can hide/remove the existing search input field. Or maybe DataTables has a setting to remove/not-include it.

    Checkout the Datatables API documentation on this.

    Example:

    HTML

    
    

    JS

    oTable = $('#myTable').DataTable();   //pay attention to capital D, which is mandatory to retrieve "api" datatables' object, as @Lionel said
    $('#myInputTextField').keyup(function(){
          oTable.search($(this).val()).draw() ;
    })
    

提交回复
热议问题