Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll issue in Jquery DataTable

I am not sure if I am repeating the question if yes guide to the right place :)

I am using Data table and trying to implement Horizontal Scrolling and found this link

http://www.datatables.net/examples/basic_init/scroll_x.html

i used these properties in my Data Table code and am having issues in UI.

My data got the horizontal scroll bar but my columns didn't expand and not working as expected.i got additional empty column below my normal column.

Basically my UI is messed up. i saw a old thread discussion on the same!

DataTables fixed headers misaligned with columns in wide tables

Are these issues fixed now any solutions ?

================================

Adding sample code

$("#results").dataTable({
    "aaData": [
        //My data
    ],
    "aoColumns": [
        //My Columns
    ],
    "bPaginate": true,
    "bSort": true,
    "bFilter": false,
    "bJQueryUI": false,
    "bProcessing": true,
    "sScrollX": "100%",
    "sScrollXInner": "110%",
    "bScrollCollapse": true
});
like image 965
user2067567 Avatar asked Apr 18 '13 07:04

user2067567


People also ask

How to enable scroll in DataTable?

DataTables has the ability to show tables with horizontal scrolling, which is very useful for when you have a wide table, but want to constrain it to a limited horizontal display area. To enable x-scrolling simply set the scrollX parameter to be true .

What is scroll collapse in DataTable?

The DataTable also exposes a powerful API that can be further used to modify how the data is displayed. The scrollCollapse option is used to specify whether the table will collapse when the scrollY option is used to determine the maximum height of the table.

How do you scroll a table in HTML?

Very easy, just wrap the table in a div that has overflow-y:scroll; and overflow-x:scroll properties, and make the div have a width and length smaller than the table. IT WILL WORK!!!

How do I add a horizontal scrollbar to a div?

For horizontal scrollable bar use the x and y-axis. Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line.


1 Answers

I had a similar issue, but solved it in a different way.

I modified the sDom parameter to wrap the table in an extra div:

sDom: 'r<"H"lf><"datatable-scroll"t><"F"ip>',

I then applied the following styles to the .datatable-scroll class:

/**
 * Makes the table have horizontal scroll bar if its too wide for its container
 */
.datatable-scroll {
    overflow-x: auto;
    overflow-y: visible;
}

http://datatables.net/usage/options#sDom

like image 169
Petah Avatar answered Sep 30 '22 22:09

Petah