You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
By default it shows 25. When I select 50 as perPage, it shows me 50. When I now go to page 2, it triggers two calls, which retrieves data from DB, twice. Once with correct perPage parameter and once without.
/test?page=2
/test?page=2&perPage=50&sort=name
After digging a bit in code I found the problem in Table.vue providing function "function visit(url)" to Pagination.vue as onClick handler:
As soon as one of the numbers gets clicked, it calls visit, which calls the passed URL. the URL however is a static set of URLs, dot being modified when perPage or any filter gets updated. Instead urls of the following kind are called: https://myserver/test?page=2
In "visit" method, the mnodel is updated: queryBuilderData.value.page = queryBuilderProps.value.page
and this triggers
which finally calls the second visit with the correct parameters, refreshing the page with correct values.
I am not too deep into this project though, so I open it as an issue and maybe someone finds a better solution. For me to avoid those problems, I created a "CustomizedTable.vue" and added a new method, which is called on page change and which only updates the model, thus calling visit implicitely, once, instead of calling visit also explicitely.
function onSetPageChange(url) {
let pageName= $inertia.page.props.queryBuilderProps[props.name].pageName??'page';
let tmp = url.split('?');
if (tmp.length == 2) {
tmp = tmp[1];
} else {
tmp = "";
console.log("Expected URL to contain a single ?");
}
// Using Proxy class is fastest solution to date
// See https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
const params = new Proxy(new URLSearchParams(tmp), {
get: (searchParams, prop) => searchParams.get(prop),
});
let value = params[pageName];
queryBuilderData.value.cursor = null;
queryBuilderData.value.page = value;
}
I guess there are better ways to do this, I did not want to abuse the label, so maybe the whole data model should be extended. Then I passed this method to Pagination like:
<Pagination
:on-click="onSetPageChange"
In the end I still ended up with a second call (this time with identical parameters) as visit() changes the parameters which triggers the watch. As the parameters were equal, I just catched it with s stupid if statement in the onSuccess method of visit():
if (queryBuilderData.value.cursor != queryBuilderProps.value.cursor) queryBuilderData.value.cursor = queryBuilderProps.value.cursor
if (queryBuilderData.value.page != queryBuilderProps.value.page) queryBuilderData.value.page = queryBuilderProps.value.page
This is not very clean code but did the job now and as I spend a LOT of hours today on debugging why my tables behave strangely, I will probably use this workaround unil there is a nicely done fix.
The text was updated successfully, but these errors were encountered:
mbeckerle-xqueue
changed the title
Pagination submits two requests
Pagination: changing page submits two requests
Jan 31, 2023
I was about to investigate why tables tend to flicker on page change and set up a very simple table.
My controller:
My vue with table:
By default it shows 25. When I select 50 as perPage, it shows me 50. When I now go to page 2, it triggers two calls, which retrieves data from DB, twice. Once with correct perPage parameter and once without.
After digging a bit in code I found the problem in Table.vue providing function "function visit(url)" to Pagination.vue as onClick handler:
As soon as one of the numbers gets clicked, it calls visit, which calls the passed URL. the URL however is a static set of URLs, dot being modified when perPage or any filter gets updated. Instead urls of the following kind are called: https://myserver/test?page=2
In "visit" method, the mnodel is updated:
queryBuilderData.value.page = queryBuilderProps.value.page
and this triggers
which finally calls the second visit with the correct parameters, refreshing the page with correct values.
I am not too deep into this project though, so I open it as an issue and maybe someone finds a better solution. For me to avoid those problems, I created a "CustomizedTable.vue" and added a new method, which is called on page change and which only updates the model, thus calling visit implicitely, once, instead of calling visit also explicitely.
function onSetPageChange(url) {
I guess there are better ways to do this, I did not want to abuse the label, so maybe the whole data model should be extended. Then I passed this method to Pagination like:
In the end I still ended up with a second call (this time with identical parameters) as visit() changes the parameters which triggers the watch. As the parameters were equal, I just catched it with s stupid if statement in the
onSuccess
method of visit():This is not very clean code but did the job now and as I spend a LOT of hours today on debugging why my tables behave strangely, I will probably use this workaround unil there is a nicely done fix.
The text was updated successfully, but these errors were encountered: