Free jqGrid 4.8.0 - restore grid toolbarfilter values

一个人想着一个人 提交于 2019-12-13 06:51:03

问题


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.


回答1:


I think that if you already filled all fields of the filter toolbar then you can just call triggerToolbar method. Be carefully that the method is method of DOM element. So you can just call

$grid[0].triggerToolbar();



回答2:


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]);
				}
}


来源:https://stackoverflow.com/questions/29416960/free-jqgrid-4-8-0-restore-grid-toolbarfilter-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!