Dynamic loading with server sort - incorrect request parameter (start)

DataTable cannot handle this scenario:

  1. scroll down several pages of data, e.g. 500 records
  2. sort Name column
  3. when scrolling up, requests with an incorrect “start” parameter are generated (e.g.: start: 0, start: 504, start 503, start: 502 …)

see:
https://snippet.webix.com/cpv0fx9k

Datatable should be able to handle this scenario.
Possible options include:

  1. clear data and start from start: 0
    or
  2. clear data continue downloading from the last position

What scenario do you propose in such a situation?

1 Like

Hi @AndS

Considering the suggested alternatives, the most feasible option is resetting scroll position to 0 when sorting is applied: Code Snippet

However, the overall behaviour corresponds to our general principles of dynamic loading.

Server-side sorting is data reloading with certain parameters. When a Webix widget reloads data, the 1st request always starts at 0 position (also, when a component is initialized, the initial request can have no parameters at all - dynamic loading is enabled based on the first server response).

Sorting preserves scroll position (filterinig does the same if possible), and as a result, an additional request is made to load data at the visible area of the datatable.

The same can be observed if the scrollTo method is called with custom values (in pixels).

The start is not necessary a multiple of datafetch (50 by default) and depends on the current scroll position and on already loaded data items (so it can be 503, 506, etc.). Still, datafetch determines the size of expected portion of data.

With that said, when scrolling up from a certain position after sorting, start is decreasing by the datafetch value to avoid any gaps. If you scroll all the way to the top, the last request/response will include the existing data, but this won’t duplicate records - any incoming item with a matching ID will be treated as an update and won’t cause any conflicts.

1 Like

Thank you, scrollTo generally solves the problem.

But, never mind sort, there is some bad behavior (see start value in requests)
Example:
https://snippet.webix.com/chmx1ecm

  1. Quick scroll down the list, e.g. halfway and I see the first record at the top of the list, id:472.
    In the console I have a request:
    https://docs.webix.com/samples/server/packages_dynamic?start=469&count=50&continue=true
  2. gently scrolls up to record id:471.
    I see two requests in the console:
    https://docs.webix.com/samples/server/packages_dynamic?start=998&count=50&continue=true
    https://docs.webix.com/samples/server/packages_dynamic?start=468&count=50&continue=true
  3. scrolls up one record again to id:470.
    I see two requests in the console:
    https://docs.webix.com/samples/server/packages_dynamic?start=998&count=50&continue=true
    https://docs.webix.com/samples/server/packages_dynamic?start=467&count=50&continue=true
    e.t.c

In my opinion, this behavior is wrong:

  1. why the request is sent: start=998&count=50&continue=true
  2. scroll up should download the all previous page and set start = currentPos - datafetch(i.e:50)
  3. (NEW PROBLEM!!!) scroll by keyboard key “Up” doesn’t scroll the page up (just stop on the first list record)

Does the owner of webix read the forum?
I’m raising the issue

Hello @AndS ,

I apologize for the late response and for any inconvinience caused by it.
First of all, thank you for the detailed reports.

why the request is sent: start=998&count=50&continue=true
scroll up should download the all previous page and set start = currentPos - datafetch(i.e:50)

I can confirm the bug, thank you!
It appears when scrolling by dragging a scrollbar (but not via mousewheel), so I’m assuming that our onscroll handler is triggered twice in this specific case (2nd time coordinates and/or direction could be mishandled - in that case, loader simply fetches the next possible portion towards the end of the dataset).

(NEW PROBLEM!!!) scroll by keyboard key “Up” doesn’t scroll the page up (just stop on the first list record)

Definitely a bug, thank you!

We’ll do our best to fix both issues in one of the nearest minor updates.

1 Like