Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination - Remove extra query variable from page url #727

Open
ldecoker opened this issue Jan 25, 2022 · 5 comments
Open

Pagination - Remove extra query variable from page url #727

ldecoker opened this issue Jan 25, 2022 · 5 comments

Comments

@ldecoker
Copy link

|---------------- | ------
| Bundle version | 5.8.0
| Symfony version | 5.4
| PHP version | 7.4

Hello,

I got a list that I displayed using paginator. Under this list, I have added the pagination using the knp_pagination_render.

After deleting a record in a list, I used an ajax call to regenerate the list and so the pagination. To differenciate this ajax call from a normal one, I used a query variable "ajax". My issue is even if I removed the "ajax" variable from the query, when the pagination is rendered, it does include it, which break the page display when I want to go to another page.

is there a mechanism that would allow me to remove this extra query param from pagination?

thx!

@garak
Copy link
Collaborator

garak commented Jan 25, 2022

You should use appropriate Request method to detect ajax calls

@ldecoker
Copy link
Author

Hello!
In the method to generate the list and the pagination, I am using at first thing:

if ($request->query->get('ajax' )) { $request->query->remove('ajax'); $template = '_list.html.twig'; } else { $template = 'list.html.twig'; }

So I would expect that the ajax variable should not be used by the pagination render method. And indeed if I dump the query params after that, it's not in anymore. I surely miss something.

Thx!

@garak
Copy link
Collaborator

garak commented Jan 26, 2022

Let me be more clear (sorry but yesterday I replied from my mobile): you should use isXmlHttpRequest method instead of relying on a query parameter.

@ldecoker
Copy link
Author

I am using fetch for my ajax calls and if I am not wrong, it does not send the needed information for isXMLHttpRequest.

@garak
Copy link
Collaborator

garak commented Jan 26, 2022

I am using fetch for my ajax calls and if I am not wrong, it does not send the needed information for isXMLHttpRequest.

You just need to use the proper header, something like this:

const req = new XMLHttpRequest();
req.setRequestHeader("X-Requested-With", "XMLHttpRequest");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants