4

I am using DataTables plugin with Responsive Table and fixed yScroll and disabling xScroll.

But I am still getting the Horizontal Scrollbar, though I am adding the code like below...

scrollY: 200,
scrollX: false,

Screenshot Ref: enter image description here

Anyhow, I am using Responsive table, why I want to show the Horizontal Scrollbar?

Because of this, Expand / Collapse on Columns functionality also not working...

Please refer the code, online example and screenshot below...


Online Demo


CSS

th,td{white-space:nowrap;}

If I remove above css it is working as expected. But I dont want to wrap down the td / th text. This is where I am facing problem :(

jQuery:

$(document).ready(function() { 

  var table = $('#example').DataTable( {
    dom: 'RCT<"clear">lfrtip',

    scrollY: 200,
    scrollX: false,

    columnDefs: [
      { visible: false, targets: 1 }
    ],

    "tableTools": {
      "sRowSelect": "multi",
      "aButtons": [
        {
          "sExtends": "print",
          "sButtonText": "Print"
        }
      ]
    }

  });
});

HTML

<table id="example" class="display responsive" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>

    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>
.....................
5
  • Remove CSS rule th,td{white-space:nowrap;} to get rid of horizontal scrolbar. Commented Aug 4, 2015 at 14:06
  • @Gyrocode.com... Thanks for that.. but some reason, I have to maintain 'nowrap' property in my application :( Commented Aug 4, 2015 at 14:16
  • Then I'm afraid, it will not be possible. There are other issues with your set-up as well, such as "Position" header shown, click on name cell result both in row select and plus sign open/close, responsive plug-in doesn't seem to work, etc. And it's not recommended to load files from https://www.datatables.net where access would be blocked, use //cdn.datatables.net instead. Commented Aug 4, 2015 at 14:50
  • Yes @Gyrocode.com, if I remove white-space property then only expand/collapse is working... :( Commented Aug 4, 2015 at 14:53
  • Is there a reason why you cannot change body{margin:50px;max-width:700px;} to body{margin:50px;max-width:900px;}? Commented Aug 7, 2015 at 19:30

3 Answers 3

1
+50

Change this from:

columnDefs: [
  { visible: false, targets: 1 }
],

To:

columnDefs: [
  { targets: 1 }
],

And the horizontal scrollbar goes away.

Working fork: http://cssdeck.com/labs/qfeibp13

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @UncleRico, Its working like champ... Awarded 50 points for your smart answer with Demo... Thanks a LOTTT
Well, according to the documentation, targets marks the num of column where a corresponding option should be applied. So, if you don't need the option, you don't have to specify a targets; you just delete the columnDefs all. visible: false means you want to hide this column in targets.
1

Add className: 'none' to your columndefs

columnDefs: [
  { className: 'none', targets: 1 }
]

Looks to be a conflict between the responsive addon and the visibility hidden option.

Comments

0

If you are using Responsive, then Responsive will decide the columns visibility. If you don't want the data from a specific column to be shown then use the "never" class as follows.

"columnDefs": [ {
    /*"visible": false, <- this does not work with responsive*/
    "className": "never",
    "targets": 0,
    }]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.