jump to page with data row xyz - after ordering

jump to page with data row xyz - after ordering

veloopityveloopity Posts: 87Questions: 36Answers: 2

I need to highlight a certain row in the table, and the page containing this row needs to be displayed after loading the page.
That works, so far - I even managed to call a function on pagination change that highlights that row again if I set the table pagination to 5 or 25 or 50 rows, etc.
Now when a column header is clicked and the order is changed, the same needs to happen - after ordering, the new rowID of the highlighted row is retrieved from Ajax in a session variable, the new page number is computed, and the page needs to jump there. Where do I put this? when I put it in a function that is triggered by the order event, and then jump to the page, I seem to get into a loop (judging from an alert I added here).

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    seem to get into a loop (judging from an alert I added here).

    I don't see the alert message but you could be causing the Datatables events to fire in a circular loop.

    I don't understand what you are trying to achieve. But it sounds like you are trying to display a particular row on different Datatables events. Have you looked at just using the draw event?

    Can you post a link to your page are a test case showing the issues so we can see what you are doing to offer suggestions?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • veloopityveloopity Posts: 87Questions: 36Answers: 2

    no no, the alert was in my code and it kept coming up so I knew I was stuck in a loop :)

    What I'm trying to achieve: a particular row must stay highlighted (DT should always jump to the page that has this row), also after clicking a header column to reorder the data. I know how to highlight a row and how to jump to page number xyz but I don't know where to catch that order event (so that I can add a jump to page xyz there) without creating a loop. I've tried the draw event I think but of course, when I add the jump to page statement there, this creates another draw event and bang - I'm in a loop. The same happened when I tried the order event. Maybe I need to somehow detect when I'm already on the correct page and then not jump? hmm ... I need to try that

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited August 2022 Answer ✓

    We haven't seen any code of what you are trying to do so its impossible to help debug. Please post a test case showing what you are doing so we can help debug and offer suggestions.

    How are you jumping to the page? Are you using the page.jumpToData() or row().show() plugins?

    You are right if you are calling draw() then you could run into recursion issues. Instead of using table.on('draw'), for example, you might be able to use jQuery one() for a one time event. But again we will need to see what you are doing to help with this.

    Kevin

  • veloopityveloopity Posts: 87Questions: 36Answers: 2

    hi Kevin, it all seems to work now - the data row that needs to be highlighted stays highlighted even after reordering, datatables always jumps to the page that contains that data row.
    But now I can't manually jump to another page by clicking on "previous" or "next" or one of the page numbers in the lower right - I am always sent back to the page with the highlighted data :) is there a way to detect that the user has clicked on a pagination page number, so that I can suppress my page-jump-to-highlighted-row mechanism?

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    The page event is used for detecting page events.

    Kevin

  • veloopityveloopity Posts: 87Questions: 36Answers: 2

    the page info that is returned from the page event doesn't tell me what the user has clicked on. The page gets drawn whenever I click on a column or a page number or if I change the pagination length. For my situation, I need to detect when the user explicitely clicks on the page links in the lower right (first,prev,pagenumber,next,last). Is that possible?

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    See if the technique in this thread helps. I believe the pagination div is rebuilt each the table is drawn. So you might need to create this event handler in the draw event.

    Kevin

Sign In or Register to comment.