Reputation: 1328
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.
Upvotes: 0
Views: 1601
Reputation: 2244
table.ajax.reload(null,false);
the second parameter is used for keep page state.
Upvotes: 0
Reputation: 28099
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.
Upvotes: 2
Reputation: 1328
I figure out the answer already. I can use bStateSave options but the value has got to be a string. That means I need to use "true" instead of Boolean true.
Here is the code fragment that works
options.put("bStateSave", "true");
Another way is not to refresh the datatable.
Here is the code fragment that works in tml
<a t:type="eventLink" t:event="review" t:context="[rowUser.id]" href="#" t:zone="^">Test</a>
Upvotes: 0