quasar icon indicating copy to clipboard operation
quasar copied to clipboard

Possible loop on datatable with server-side interaction

Open danielo515 opened this issue 8 years ago • 5 comments

Software version

Quasar: 0.15.2 OS: MacOS X Node: 8.10 NPM: 5 Browsers: Chrome

JsFiddle (for Quasar v0.15+ only)

What did you get as the error?

I don't get any error, the problem is the behavior

What were you expecting?

I expect to not trigger the server-side pagination more than once per server interaction.

What steps did you take, to get the error?

I'm going to explain the entire problem here.

This is related to datatable and server-side pagination/filtering. Reading the following two code snippets related to pagination it becomes clear what the problem is:

This is how pages number is calculated

https://github.com/quasarframework/quasar/blob/66c5a046191b1d6942a3d1825e292116d16b63bd/src/components/table/table-pagination.js#L37-L40

This the watcher of pages number and the set pagination method

https://github.com/quasarframework/quasar/blob/66c5a046191b1d6942a3d1825e292116d16b63bd/src/components/table/table-pagination.js#L55-L83

Now think about what will happen if the server returns an empty list of results. Rows number will be 0, so pagesNumber will return 0. Because of this, pagesNumber watcher will evaluate the second if to true (because last page is 0, and currentPage is 1) and will call setPagination, which in turn will call requestServerInteraction (with page set to 0!) which will call the server again, who will return an empty results list again (2 server trips for now). If you just trust the reported page (0) and saves it depending on your situation this may be a problem: if your pagination is 0 based, and you subtract 1 from the reported page (because datatable is 1 based) you will end requesting the -1 page to the server. At this point because the watcher looks for changes the loop may end here, but if you modify the page in any way to keep it at 1 for example, it will be different from the last page (0) and it will trigger again.

I'm not sure how to fix this on quasar itself. Maybe it is not a good idea to allow pagesNumber to become 0, and it should be set to a minimum of 1.

Regards

danielo515 avatar Mar 24 '18 16:03 danielo515

Fix available in 0.15.11

rstoenescu avatar Mar 30 '18 07:03 rstoenescu

Hi,

I've been testing the dev branch and the new fixPagination code you added :

if (p.rowsPerPage !== void 0 && p.rowsPerPage < 1) {
    p.rowsPerPage = 5
  }

Causes the "All" rowsPerPage to be set back to 5 rows per page instead. Option All = 0 as you know...

Lou-Der avatar May 11 '18 01:05 Lou-Der

To be honest, using 0 which has a meaning of, well zero, to flag all seems like a bad design decission

danielo515 avatar May 11 '18 06:05 danielo515

@Lou-Der will investigate. thanks for reporting. @danielo515 yes, because displaying 0 rows makes so much sense, right? :)))

rstoenescu avatar May 11 '18 13:05 rstoenescu

True, I was thinking about page zero, not zero rows

danielo515 avatar May 14 '18 08:05 danielo515