Im hoping this is a fairly simple problem.
Im trying to use Datatables to create a table without any horizontal scrolling. The table has some long data rows which I need to keep on one line and hide the overflow.
It seems like I'm missing something fairly basic with datatables here, but I can't seem to get rid of the horizontal scrollbar when the table gets a vertical scrollbar.
http://jsfiddle.net/FBpLA/3/
There are two tables (identical data), both are initialised very simply.
$('#mytable').dataTable({
bFilter: false,
bInfo: false,
bPaginate: false,
});
$('#mytable2').dataTable({
bFilter: false,
bInfo: false,
bPaginate: false,
sScrollY: '150px'
});
The styles for the page are fairly straight forward
body {
height:100%;
color: #000000;
font-family: Helvetica, Arial, Verdana, sans-serif;
font-size: 10pt;
background-color: #B4D4EC;
}
.main-panel {
display:block;
background:white;
padding:20px;
height: 100%;
position:absolute;
width: 700px;
top: 139px;
bottom: 110px;
}
th {
text-align:left;
}
td {
border-spacing:0;
white-space:nowrap;
overflow: hidden;
text-overflow: ellipsis;
-ms-text-overflow:ellipsis;
}
The scrollbar you added in jquery datatable is encapsulated. It comes with the style of the scrollbar. You can override the original style of the scrollbar by rewriting the style in the page, which hide the Scroll Icons.
Web browsers do not take into account the width of the scrollbar on the side of a page when computing width values, so since we have a page that is longer than a single viewport, part of our page is being rendered behind the vertical scroll bar, causing the browser to display a horizontal scroll bar.
Many assume that width: 100vw is the same as width: 100% . This is true on a page that doesn't scroll vertically, but what you might not realize is that the viewport actually includes the scrollbars, too.
Approach: Scrollable Horizontal Menu is used to scroll the horizontal navbar using CSS “overflow:auto” and “white-space: nowrap”. These two attributes are used to scroll the horizontal menu. To implement the scrollable horizontal menu. You have to add HTML. You have to add CSS to the code.
In the end the best solution was to set the width of the inner table to:
table-layout:fixed;
width: 98% !important;
All solutions listed here had undesirable cropping behavior. Limiting the table width in this way also allowed me to dynamically adjust the height of the table such that the horizontal scrollbar can appear or disappear on demand without introducing an horizontal scroll.
http://jsfiddle.net/FBpLA/15/
.dataTables_scrollBody
{
overflow-x:hidden !important;
overflow-y:auto !important;
}
this worked for me for all of my tables. This was also only an issue with firefox and IE, chrome handled it just fine to begin with.
You can just add overflow-x: hidden;
to the .dataTables_scrollBody
if you can't find something that fixes it natively in the script. Unfortunately, you'll probably also need to use !important
to raise its specificity higher than the inline styles applied to the element already.
http://jsfiddle.net/SombreErmine/FBpLA/12/
You can use the css tag overflow-x:hidden;
to remove the horizontal scrollbar on the table with id mytable2
.
#mytable2
{
overflow-y:scroll;
overflow-x:hidden;
}
However, if you use table-layout:fixed
this won't work, a majority of the browsers will treat the overflow in their naturual behaviour rather than watching the css.
Some info on table-layout:fixed
by Mozilla: https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout
Example fiddle: http://jsfiddle.net/FBpLA/9/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With