How to place the dataTables#39; horizontal scrollbar on top of the table?(如何将 dataTables 的水平滚动条放在表格顶部?)
问题描述
I have a really large datatable and I want to put the horizontal scrollbar on top as well as on the bottom of the table so it would be easier for the user to scroll (the datatable has a lot of columns). Is there an easy and proper way to achieve this?
You can use a container that has a maximum width and put the table inside.
Depending on how much reliability you want, you can make:
A. Bottom scrollbar, just set a maximum width and overflow x to scroll:
Demo:
B. Top scrollbar, a little hacky, use a 180 degree transform to rotate the scrollbar to the top, then again another 180 degree to put back the content.
You may want to use broswser specific prefixes for transform, like -webkit-transform:rotateX(180deg);
.
Demo:
C. Top and bottom scrollbar, a little more hacky. Needs some javascript. Use the solution form A above and add a 'fake' div for top scrollbar:
And a little javascript to catch the scroll on the top fake div and then scroll the table container (and vice-versa), with jQuery:
Demo:
The working complete code for all three solutions:
这篇关于如何将 dataTables 的水平滚动条放在表格顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!