Reputation: 2457
I'm having an issue where I'm putting jQuery DataTable in an bootstrap 3 panel will cause the search box and page numbers to go off.
Here is the design:
I have a webpage, and will have multiple jQuery DataTable, however, with a large number of columns, it will make the webpage scrollable horizontally.
Hence my idea is to use the bootstrap 3 panel feature, and put the datatable inside, hence it will now only scroll the panel, but not the whole webpage.
Hence, the final result is a nice looking table inside the panel.
However, when the panel starts to scroll horizontally, the search and page tabs are not placed to the far right side, but in the middle, which it will look like this after it scrolls.
Can anyone point me to the right direction on how I could put the search and page tabs to the far right?
Upvotes: 1
Views: 2465
Reputation: 2927
The best way to keep your search bar at the end of your table AND keep a scrollable table is to use scrollX
in the DataTable attributes. ScrollX
Upvotes: 2
Reputation: 9157
Simple workaround - disable default search field, make a custom input field for datatables search and place it in bootstrap panel.
var oTable = $('#datatable').dataTable({
// ... options ...
});
$('.custom-input-field').keyup(function(e){
oTable.search($(this).val());
oTable.draw();
});
setTimeout
would be a good idea in this case:
var searchTimer;
$('.custom-input-field').keyup(function(e){
clearTimeout(searchTimer);
var keyword = $(this).val();
searchTimer = setTimeout(searchTable, 1000, keyword);
});
function searchTable(keyword){
oTable.search(keyword);
oTable.draw();
}
Upvotes: 1