Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove default search box and add custom one in jquery datatable

I am using jquery datatable. My required is to remove default search box and add custom one in difference place. I use bFilter:false for remove the search input but it is also disabling search filter functionality. Any Idea how to fix it without using css fiddle

$(document).ready(function(){    
   var table= $('#example').DataTable({
        paging:false,
        bFilter:false,
        ordering:false
    });

    $('#search-inp').keyup(function(){
      table.search($(this).val()).draw() ;
})

});
like image 715
Jitender Avatar asked Apr 21 '15 10:04

Jitender


People also ask

How to remove search box in jquery dataTable?

$('table'). dataTable({searching: false, paging: false, info: false});

What is Bfrtip dataTable?

The B is the Buttons extension and it tell DataTables where to put each element in the DOM that it creates.


2 Answers

For Hiding Default Search Input box of Data tables AS:
by default sDom="lftipr";

Perform these operations on datatables
'l' - Length changing
'f' - Filtering input
't' - The table!
'i' - Information
'p' - Pagination
'r' - pRocessing
For removing default search box just remove the f character from sDom.

like:

$('#table').DataTable({
  "sDom":"ltipr"
});

Hope this must work

like image 141
Omer Butt Avatar answered Sep 18 '22 12:09

Omer Butt


You can use the dom option to hide the search input without disabling the search functionality. This is useful if you want to provide your own inputs for searching (perhaps on a column by column basis, or globally). It also accomplishes what you asked for initially - remove the original search input without using CSS.

Here is the documentation: https://datatables.net/examples/basic_init/dom.html

And, of course, an example:

var table = $('#example').DataTable({
        paging: false,
        bFilter: false,
        ordering: false,
        searching: true,
        dom: 't'         // This shows just the table
    });

You could also use this method to render the search input in a different place. Depending on where you need to render the input, you may be able to avoid using a custom one altogether.

like image 26
ithinkisam Avatar answered Sep 17 '22 12:09

ithinkisam