Search code examples
jqueryjqgridfree-jqgrid

Free jqGrid 4.8.0 - restore grid toolbarfilter values


I'm trying to restore the grid after doing GridUnload to it's previous state in terms of filter, sort, group etc'. I successfully achieved restoring all of those, but missing some visual aspects within the grid that are not part of the data i'm restoring, and as such I can't see them.

For example, I do restore the filter values (toolbarfilter), but I can't see the filters values in the toolbar. (they are there, as I can restore them using $("#gview_"+$grid.attr('id')+' #' + inputId).val(column.data), but I don't know how to make them re-appear without iterate manually over them.

Thanks,

Tal.


Solution

  • Eventually, I restored the toolbarfilter by doing the following:

    1. I saved all the rules into a temporary varible (barFilter).
    2. After grid restoration, I added a new function that gets the barFilter and extract the values into their places restoreToolbarFilter($('#'+gridName),barFilter);:

    regexEscape = function(s) {
    			return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
    };
    
    function restoreToolbarFilter($grid,searchParams){
    	
    				
    				for (key in searchParams) {
    					// Restore the search input string
    					var column = searchParams[key];
    					
    					inputId = regexEscape('gs_' + column.field);
    				
    					
    					$("#gview_"+$grid.attr('id')+' #' + inputId).val(column.data);
    					
    					// Restore the search filter type and operator symbol
    					operator = $("#gview_"+$grid.attr('id')+' #' + inputId).closest('tr').find('.soptclass');
    					$(operator).attr('soper', column.op);
    					operands = {  "eq":"==",
    									"ne":"!",
    									"lt":"<",
    									"le":"<=",
    									"gt":">",
    									"ge":">=",
    									"bw":"^",
    									"bn":"!^",
    									"in":"=",
    									"ni":"!=",
    									"ew":"|",
    									"en":"!@",
    									"cn":"~",
    									"nc":"!~",
    									"nu":"#",
    									"nn":"!#" };
    					$(operator).text(operands[column.op]);
    				}
    }