Changing DOM Element Position of searchbox in datatables

前端 未结 8 1830
春和景丽
春和景丽 2021-01-30 14:57

Actually I am new to jQuery datatables plugin.

I have attached the plugin to my tables using this method using this code.

$(document).ready(function() 
         


        
8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 15:16

    For the actual version in Dec 2018 (v1.10.19) you need to do this steps:

    1. Hide the default search box (CSS):

      .dataTables_filter { display: none; }
      
    2. Add new filter to your desired place (HTML)

      Search:
    3. After your DataTables inicialisation function you need to write your search function (JS):

      $(document).ready(function() {
         var table = $('#example').DataTable();
      
      $('#searchFilter').on( 'keyup', function () {
         table.search( this.value ).draw();
      } );
      

    Note: fnfilter is deprecated, so use search(), but search() doesn't redraw the table, so you need to use draw() too.

提交回复
热议问题