0

I'm currently involved in a project that uses Grails, and using JqGrid as the main plugin for displaying tables. Data from tables is fetched from the database using Grails.

The problem is maintaining the table's persistence (like filter and list order) when moving to the other page. Because each table has its own set of pages (edit page, show page) and whenever i move from list page to edit page, and return back to the table page, the list's filtering will gone.

I've checked in here on how others did it like in here, and mostly it involves with cookies. But i was told that if possible to not rely on cookies due to security issues. I've done the coding to grab the filter from the jqGrid.

function saveFilter(grid){
var colModel = $(grid).jqGrid('getGridParam', 'colModel');
var colNames = $(grid).jqGrid('getGridParam', 'colNames');
var colNamesLength = colNames.length - 1;
var value = [];

for (var i = 0; i < colNamesLength; i++){
    value[i] = $("#gs_"+colModel[i].name).val();
};

prefs = {
    value: value,
    grid: grid,
    colNames: colNames,
    colModel: colModel,
    sorn: $(grid).jqGrid('getGridParam', 'sortname'),
    sord: $(grid).jqGrid('getGridParam', 'sortorder'),
    page: $(grid).jqGrid('getGridParam', 'page'),
    rows: $(grid).jqGrid('getGridParam', 'rowNum')
};
}

Now the thing is, where do i go from here? Since i'm most likely cannot save the prefs as cookie, what other options could i possibly have? The prefs are needed to reload back the grid to its filtered condition after i return back from either edit or show page.

Is it possible to send the prefs to the controller, and have it send back to the jqGrid upon returning back to the list page? Or is Grails have this kind of feature that allows persistence in the list?

Thanks

Community
  • 1
  • 1
Fred A
  • 1,602
  • 1
  • 24
  • 41
  • Have you tried serialising this or create a model and post it back to controller that can save it. If you are not storing filters then you may not even need to serialise. – Farrukh Subhani Jun 11 '14 at 17:32
  • Yeah i tried sending the data to the controller and tried to return it back to the JS through the GSP, but for this to work i need to declare the variable as static in the controller in order to pass the data to the other functions whenever i switched pages, which is no good because all users can access to that same data. In the end i gave up the idea of passing the data to controller, and instead just work it out from JqGrid level, using sessionStorage. Anyway thanks for the input. Appreciate it. – Fred A Jun 13 '14 at 03:23

0 Answers0