20

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() ;
})

});
1
  • 1
    Just remove the <input type="text" id="search-inp"> and keep the id to set it to your custom input, you can also place it wherever you need (I managed to place the search text at bottom, so technically you can do whatever you want). Commented Apr 21, 2015 at 10:49

5 Answers 5

30

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

Sign up to request clarification or add additional context in comments.

2 Comments

This uses the legacy API and is a suitable answer if you can't upgrade to the current version of DataTables.
let oTable = $('#tableName').DataTable({ "sDom": "ltipr", "searching": true)}; there are other options to hide that box searching: false but that also stops custom filtration on client side. So this is the most logical answer as custom searching/filtration is still working.
27

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.

Comments

7

bFilter actually removes the search functionality so what I suggest it just hide the default search and then you can implement your custom search with the code you have already written. Just check below code:

#example_filter //#example is your table id, so you can replace it with whatever Id you give to table
{
    display:none;
}

Note : Remove bFilter during initialization

Then your normal coding. Here is the DEMO

Comments

1

As Guruprasad mentioned, 'bfilter': false removes the search functionality. So you need to use the 'dom' option.

Also dom comes with markup and styling functionalities. So if you need the exact datatable styling then you should use

$('#example').dataTable( {dom: '<"row"lr><"row"<"col-xs-12"t>><"row"<"col-sm-6"i><"col-sm-6"p>>'});

Comments

0

Simply add this to your css
.dataTables_filter { display: none;}

it will hide default search box and you can use your own search box, there is no need for bfilter : false

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.