Datatables(JQuery plugin) has scrollx option, which when set to true will add scroll bar that will appear at the bottom of your table, is there an option to also display it at the top of your table.
Datatables(JQuery plugin) has scrollx option, which when set to true will add scroll bar that will appear at the bottom of your table, is there an option to also display it at the top of your table.
Share Improve this question edited Jun 27, 2014 at 13:56 GMoney asked Jun 27, 2014 at 13:48 GMoneyGMoney 2055 silver badges11 bronze badges 1- it's browserly impossible, unless Google Chrome decide to have a CSS rule and add this feature in... but i don't think it's happening soon @_o – Keo Strife Commented Jun 27, 2014 at 14:01
1 Answer
Reset to default 5Not quite impossible.
You find the answer at http://progrnotes.blogspot..ee/2013/07/horizontal-scrollbars-at-top-bottom-in-datatables.html: you can do it with the jQuery-doubleScroll plugin (https://github./sniku/jQuery-doubleScroll). However, this is not working with datatable which is loaded by ajax. You need to tweak it a little.
Steps to do are like this:
Download and include doubleScroll.
Add lines:
$('body').find('.dataTables_scrollBody').wrap('<div id="scroll_div"></div>'); $('#scroll_div').doubleScroll();
Add CSS
.dataTables_scrollBody { overflow-y: visible !important; overflow-x: initial !important; }
That should do it (DataTables 1.10.7)
EDIT: if you have column filters on top then the above solution needs modifying, otherwise the headers won't scroll:
Add lines:
$('body').find('.dataTables_scroll').wrap('<div id="scroll_div"></div>'); $('#scroll_div').doubleScroll();
Add CSS
.dataTables_scrollBody { overflow-y: visible !important; overflow-x: initial !important; } .dataTables_scrollHead { overflow: visible !important; }