I have added a select(dropdown) for datatables search box for searching per column and trying to add that select to searchbox as below->
var table = $('#example').DataTable({
dom: '<l<"toolbar">f>rtip',
language: {
search: "_INPUT_", //To remove Search Label
searchPlaceholder: "Search..."
}
})
$("div.toolbar").html(select);
CSS
.toolbar {
float: right;
}
It actually worked on fiddle -> https://jsfiddle.net/32v2qpj1/5/
Surprisingly length and filter position has been changing when I implemented the same on my .aspx page like below image. Bootstrap row and col grids are missing whenever I use dom. It adding as a 2 seperate rows for length and search and as same at footer. I tried examples from https://datatables.net/reference/option/dom to check if my code is wrong. It's just re-positioning when use DOM!
I have no idea why it is re-positioning when only added dom. I was wondering is there any other way to add select control to the search box?
Well. If you set the
dom
option, then you overwrite the defaultdom
setting which in dataTables with Bootstrap is :There is no reason for injecting a
.toolbar
when we have a predefined setup like this. Instead give the filter section a little more space :and define a maximum width for the
#select
:Finally add standard Bootstrap classes to the
#select
:and append the select to
.dataTables_filter
:This give the responsive experience we want from Bootstrap.
updated fiddle -> https://jsfiddle.net/32v2qpj1/6/
NB: Remember to remove
jquery.dataTables.min.css
if you use bootstrap! Instead, style the<table>
the Bootstrap way :