API plug-in to update scrollY

API plug-in to update scrollY

Loren MaxwellLoren Maxwell Posts: 272Questions: 60Answers: 9

I'm trying to develop an API plug-in to update scrollY, but I'm not sure I'm targeting the right setting or if I need to do something else to make the change happen to the table.

Here's a link to a test case:
http://live.datatables.net/tehorera/1/edit

Any thoughts on what's missing?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 9,769Questions: 25Answers: 2,255

    You have the Scroller Extension enabled which has its own APIs like row().scrollTo(). You are also getting this error in your example:

    DataTables warning: table id=example - Pagination must be enabled for Scroller

    Do you want to use Scroller for this? If not then you will want to use a Javascript or jQuery technique to scroll the table. Don't think you can just set settings.scrollY directly.

    Here is a Scroll row().scrollTo() example:
    http://live.datatables.net/yucixaju/1/edit

    Here is an example using jQuery scrollTop():
    http://live.datatables.net/suleciqu/1/edit

    If these don't help then please describe what you are trying to do.

    Kevin

  • Loren MaxwellLoren Maxwell Posts: 272Questions: 60Answers: 9
    edited July 12

    Thanks, @kthorngren. I should have been more clear.

    I'm not trying to scroll to a specific row.

    Rather I'm trying to increase the size of the scroll window from 300 pixels to 500 pixels (or whatever is passed).

    My understanding is that the height of the scroller window is controlled by the scrollY property of DataTables, so I'm trying to change that through the API.

  • kthorngrenkthorngren Posts: 9,769Questions: 25Answers: 2,255
    edited July 13 Answer ✓

    Many of the Datatables settings aren't changeable after initialization. To change the scrollY value I suspect you will need to use destroy() or destroy and re-init Datatables. I suspect this is not something you want to do.

    I would look at the scrollResize plugin. It adjusts the dataTables_scrollBody div to the height of the dragged element in the Vertical Scroll Fitting blog. This statement:

    availableHeight -= settings.container.height() - ( offsetTop + scrollBody.height() );
    

    Calculates the height based on the scrollBody.height as the element is dragged in the example. I created an example that doesn't use the draggable element but reads an input for the table height.
    http://live.datatables.net/lomugusi/1/edit

    When the input changes it simply performs a draw(). The plugin looks at the input for a value then adjusts the table to that height. The example is very simple, ie, no error checking and if you clear the input the scroll bar keeps increasing in size. Its simple to demonstrate that you can update the scrollResize plugin to do what you want. Likely there is something else that will trigger the need to change the table height other than an input.

    HTH,
    Kevin

  • Loren MaxwellLoren Maxwell Posts: 272Questions: 60Answers: 9

    Thanks, Kevin. This looks very promising!

    I'll try to implement for my specific purpose tomorrow and let you know!

Sign In or Register to comment.