I have a datatable in my web page. I need to display a horizontal scroll bar on top of the table. I have tried table.wrap('<div style="width:980px; overflow-x:auto;"/>');. It displays horizontal scroll bar at the bottom of the table. How to display scrollbar on top of the data table. Any help?
-
Check this, jsfiddle.net/TBnqw/1Manu M– Manu M2013-08-29 04:06:25 +00:00Commented Aug 29, 2013 at 4:06
-
I tried this. But it is not working with datatable which is loaded by ajax.lifeline– lifeline2013-08-29 04:10:27 +00:00Commented Aug 29, 2013 at 4:10
-
Hi - did you ever figure this out? I've got the same issue. Thanks!Max Williams– Max Williams2014-06-09 09:58:58 +00:00Commented Jun 9, 2014 at 9:58
1 Answer
You find the answer at http://progrnotes.blogspot.com.ee/2013/07/horizontal-scrollbars-at-top-bottom-in-datatables.html: you can do it with the jQuery-doubleScroll plugin (https://github.com/sniku/jQuery-doubleScroll). However, this also 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; }