Datatables - Search Box outside datatable

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

    More recent versions have a different syntax:

    var table = $('#example').DataTable();
    
    // #myInput is a  element
    $('#myInput').on('keyup change', function () {
        table.search(this.value).draw();
    });
    

    Note that this example uses the variable table assigned when datatables is first initialised. If you don't have this variable available, simply use:

    var table = $('#example').dataTable().api();
    
    // #myInput is a  element
    $('#myInput').on('keyup change', function () {
        table.search(this.value).draw();
    });
    

    Since: DataTables 1.10

    – Source: https://datatables.net/reference/api/search()

提交回复
热议问题