Pjax not working when clicking on a link within DataTables #159
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
There seems to be an issue with Pjax not detecting links within DataTables. Any ideas how to get around this?
Please link to a CodePen demonstrating the issue.
https://codepen.io/xenace/project/editor/ZgPgEK#0
What's not working? Everything looks fine to me, and the links work on all pages.
Sorry was just testing, narrowed it down to it being an issue on paginated links. If you switch to a different page and select a link it does not load through Pjax, just as a regular page load. I'm guessing that it's something to do with those links not being in the DOM when loaded.
It sounds like the elements are being dynamically generated. Try calling
pjax.parseDOM(document)after switching pages.That seems to have partly solved the issue however when clicking on the pagination links Pjax is trying to load the root page because the buttons have a href value of # i got around this before by using javascript:void(0) in the href value but would then need to override the datatable functionality to do get around this. Is there any way to tell Pjax to ignore href with # value?
Ignore last message, resolved it by setting elements to a:not(.page-link)
Just come here to add that there is actually a
pjax.refresh()method that is designed for situations like this where you need to make Pjax aware of new DOM elements which we should document properly. It is just a wrapper aroundpjax.parseDOM(), so @BehindTheMath's advice is still correct.2166866967/index.js (L69-L71)That's true. I forgot about that method.