Search code examples
jquerydatatabletapestry

Tapestry: jquery/datatable goes back to first page on reload


My jquery/datatable is in a zone. It has a column with eventlinks. It has many records, thus many pages. If I press on an eventlink on page 5 for example, and reload the datatable, it will go back to page 1. I want it to stay at the current page, page 5. The solution I found for jquery is "bStateSave": true. I tried putting that into my JSONObject getOptions() but it doesn't work. How do I make the page stay at the current page in Tapestry?

Here is my tml file

<table width="100%" t:type="jquery/datatable" t:id="list" t:source="users" t:row="rowUser" t:options="options" t:add="action"  >
 <p:actionCell >
  <a t:type="eventLink" t:event="review" t:context="[rowUser.id]" href="#">Test</a>
 </p:actionCell >

Here is my java file

public JSONObject getOptions() {
    JSONObject options = new JSONObject();
    options.put("bJQueryUI", true);
    options.put("sDom", "<\"H\"lfr>t<\"F\"ip>");
    options.put("bStateSave", true);

    return options;
}

Any help would be much appreciated. Thanks.


Solution

  • Your eventlink is non-ajax (there is no 'zone' attribute) so it will cause the page to refresh which will cause your datatable to be re-drawn.

    Have you considered using an ajax eventlink so that the page is not redrawn?

    If you still want to refresh the page after your event, you will need to use either @PageActivationContext or @Persist to store the current row between requests. I'm not familiar with jquery/datatable but I'm sure there's a way to initialize the widget to point to a specific page. You may need to calculate the page based on the selected row.

    It seems that you can use the fnPageChange function to set the current page on a datatable.