simple question: how to handle scrollY in datatables 1.10

simple question: how to handle scrollY in datatables 1.10

Pierce KrousePierce Krouse Posts: 40Questions: 8Answers: 1

I have a problem with window resizing and scrollY that I have seen discussed here before.
The problem is how to reset the value of scrollY when you detect a window resize event.
The answer is usually something like this:

var oSettings = table.fnSettings();
oSettings.oScroll.sY = whatever;
table.fnDraw();

Some answers also set .dataTables_scrollBody using a JQuery call, some only do this JQuery call, and some
just set the scrollY as seen here.

Every example I have seen uses datatables 1.9 and earlier.
Unfortunately for me, I cannot quite follow the online documents to figure out how to do this in 1.10.
I blame newness to javascript, coupled with a crippling dependency on Eclipse :-)

In all seriousness though, my code resizes the table some times, but not all the time.

I have a live example here:
http://live.datatables.net/zihireli/1/edit

This has some console output that may prove useful to watch.

But to summarize, my partial code is right here:

 windowHeight = calcWindowHeight();
var dtHeight = calcDataTableHeight();
console.log('new ht:'+dtHeight); // looks right based on the resize
// no need to set scrollY?  how to do that in 1.10 if needed?
$(".dataTables_scrollBody").height(dtHeight);
//oTable.columns.adjust().draw(); // unpredictable results, maybe scrollY will fix?

I'm happy to send my example file directly to people who may have insight into this, and any help, either with 1.10 syntax, explanations on the necessity (or not) of .dataTables_scrollBody, and/or oTable.columns.adjust().draw() would be greatly appreciated.

This question has an accepted answers - jump to answer

Answers

  • Pierce KrousePierce Krouse Posts: 40Questions: 8Answers: 1

    One other not-so simple question:

    If you click on a range of row headers (the gray boxes to the left) with click and shift-click, and then click the 'Sh' button, the rows you select are shown and the rest are hidden. However, the scroll bar remains at the bottom of the screen. It does not stick to the bottom of the table.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    This is a plug-in I wrote for 1.10 which will resize the scroll box to fit: https://github.com/DataTables/Plugins/blob/master/features/scrollResize/dataTables.scrollResize.js .

    Line 80 is the approach I used to set the height.

    However, the scroll bar remains at the bottom of the screen. It does not stick to the bottom of the table.

    It does appear to track the bottom of the table for me - Chrome 46 Mac.

    Allan

  • Pierce KrousePierce Krouse Posts: 40Questions: 8Answers: 1

    OK, thanks Allan, the scroll bar is tracking the bottom of the table for me now.

This discussion has been closed.