Possibility of triggering fetching data after resizing

Possibility of triggering fetching data after resizing

Klaus_DevKlaus_Dev Posts: 3Questions: 1Answers: 0

Link to test case: https://live.datatables.net/morunemi/1/edit

Description of problem: When resizing the space to render the table content (dt-scroll-body) to a bigger size then 9 times the displayBuffer (9 is the default according to https://datatables.net/reference/option/scroller.displayBuffer) there is no triggering of fetching additional data from the backend. Steps to reproduce and question about a better approach then mine used, see below.

Steps to reproduce, done in https://live.datatables.net/morunemi/1/edit
- Create a table loading data from a server (faked in the example)
- Initial give it a height which only shows 1.x rows
- After rendering is finished, resize the .dt-scroll-body
- Result: Only the first (1.x*9) data rows are fetched from the server
- After scrolling a lot down (with many not available rows in between) the fetching then works like expected

Idea of solution via coding
- There seems not to be any API to fetch data on demand after resizing. The only thing we can do API wise is to trigger a remeasure + redraw (sadly includes data request per-se) via table.scroller.measure(true);

Question:
Is there a better way of solving the problem of having the need to fetch data from a server after resizing the table on the UI? I don't want to have the scroller.displayBuffer always bigger then 9 because the data may be very large and "expensive"...

This question has an accepted answers - jump to answer

Answers

  • Klaus_DevKlaus_Dev Posts: 3Questions: 1Answers: 0

    Additions to what I wrote in the initial post (for whatever reason I don't find a button to edit it, that's why I add this comment):
    - The Scroller plugin for endless scrolling is used
    - Rendering via an ajax function with getting the data from a server backend is used

    The best would be, if datatables updates its buffer size by itself on resize, but I don't find any option to set or trigger this... Maybe somebody has another idea then mentioned above?

  • allanallan Posts: 63,441Questions: 1Answers: 10,465 Site admin
    Answer ✓

    There is no listener on the scroll body to tell DataTables that the height of the container has changed and that it should be updated. Only the window element triggers a resize event, so it is up to whatever caused the resize to then do a call to scroller.measure(). There is no way around that I'm afraid.

    Allan

  • Klaus_DevKlaus_Dev Posts: 3Questions: 1Answers: 0

    Hi Allan,
    thanks for this quick clarification and confirmation that "scroller.measure()" is the best way to deal with this.
    Greetings,
    Klaus.

Sign In or Register to comment.