Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing DOM Element Position of searchbox in datatables

Tags:

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()            $('#table_id').dataTable({           });  }); 

Now What I want is datatables provides a text box in which we can enter our filter string and results will be getting filtered.

So I want to use my existing designed textbox for that purpose I don't want to add a new textbox in the UI. So I gone through this link

http://datatables.net/examples/basic_init/dom.html

But I am not understanding. Is it possible to use the existing textbox. Please advice

See I was having situation like this before implementing this datatables

enter image description here

Now when I apply this datatables plugin A new text box gets added for search I don't want to a new text box I want my existing textbox to implement search functionality.

like image 991
Nikhil Agrawal Avatar asked Oct 09 '13 13:10

Nikhil Agrawal


People also ask

How do I change the position of entries in DataTables?

DataTable({ "sDom": 'Lfrtlip' }); From this you can set to bottom. Show activity on this post.

What is sDom in DataTable?

sDom. Show details. This initialisation variable allows you to specify exactly where in the DOM you want DataTables to inject the various controls it adds to the page (for example you might want the pagination controls at the top of the table).

What is lengthChange in DataTable?

The lengthChange option is used to specify whether the dropdown to change the number of rows per page is displayed or not. This dropdown is shown only when paging of the DataTable is enabled, as disabling it automatically removes the dropdown.

What is FN DataTable Isdatatable?

Description. This method provides the ability to check if a table node is already a DataTable or not. This can be useful to ensure that you don't re-initialise a table that is already a DataTable.


1 Answers

This is very simple. First you must hide the default search box :

.dataTables_filter {    display: none; } 

Example of your own designed search box, placed somewhere in the HTML :

<input type="text" id="searchbox"> 

script to search / filter when typing in the search box

$("#searchbox").keyup(function() {    dataTable.fnFilter(this.value); });     

working demo -> http://jsfiddle.net/TbrtF/

If you are using DataTables 1.10 the JS should look like:

$("#searchbox").on("keyup search input paste cut", function() {    dataTable.search(this.value).draw(); });   
like image 97
davidkonrad Avatar answered Sep 24 '22 14:09

davidkonrad