GRAILSUI Datatable - saving and restoring state between invocations
I have a datatable thru which a user can page and select a record for display .. The record replaces the the entire datatable with another one via an Ajax call .. On the second
datatable is a button to allow you to return to the first .. Currently when you开发者_开发技巧 do so you are returned to the start of the first table .. What i want to do is store the state of the first datatable (current page, offset, max records .. ) when a record is selected so i can restore it when they go back to it .. Actually storing the info is not so much of a problem - it's how to reapply it so my first table is as the user left it .??
I had a look around and found some code ..
YAHOO.util.Event.onDOMReady(function(e) {
var offset = new YAHOO.util.Element('offset').get('value');
var max = new YAHOO.util.Element('max').get('value');
var state = GRAILSUI.receiptBatchList.getState();
state.sorting = state.sortedBy;
state.pagination.recordOffset = offset;
state.paginator.rowsPerPage = max;
var query = GRAILSUI.receiptBatchList.buildQueryString(state);
GRAILSUI.receiptBatchList.getDataSource().sendRequest(query,{
success : GRAILSUI.receiptBatchList.onDataReturnReplaceRows,
failure : GRAILSUI.receiptBatchList.onDataReturnReplaceRows,
scope : GRAILSUI.receiptBatchList,
argument: state
});
where offset and max are just hiden values on the page but i can't get this to work and i'd really hoped it would be reasonably quick to implement ..
Any suggestions ?
TIA ..
As a quick hack, you can save the params' part responsible for table state from a controller action on a server side, like:
def list = {
Map savedState = userService.currentUser.tableStates['MyController']
if (savedState) {
params << savedState
}
// ... list instances
Map tableState = params.subMap(['max', 'offset', 'sort', 'order']) // add your filtering param name if you do some filtering
userService.currentUser.tableStates['MyController'] = tableState
// ... return instances
}
currentUser
, sure, has to be singleton or persistent.
精彩评论