没有卸载网格,JqGrid重新加载不起作用(JqGrid reload is not working without unloading the grid)

编程入门 行业动态 更新时间:2024-10-27 05:30:09
没有卸载网格,JqGrid重新加载不起作用(JqGrid reload is not working without unloading the grid)

我使用的是jqgrid版本4.5.2。 我在网格外部有一个角色列表组合框,并且需要更改我需要重新加载网格的选项。 下面是我的网格的定义。

var finalUrl=''; var queueStatus=jQuery('#queueStatus option:selected').val();

finalUrl =“ http:// localhost:8080 / ui / paw / loadworkflowqueuedata.raws?selRole = ”+ selectedRole +“&”+ queueStatus;

var queueStatus=jQuery('#queueStatus option:selected').val(); finalUrl= "http://localhost:8080/ui/paw/loadworkflowqueuedata.raws?timezone="+&selRole="+ selectedRole+"&"+queueStatus; jq("#grid").jqGrid('GridUnload'); jq("#grid").jqGrid({ url:finalUrl, ajaxGridOptions: {cache: false},//added the option to always reload the grid and not to cache the result. datatype: 'json', mtype: 'GET', colNames:[ 'Requestor Name'], colModel:[ {name:'requestor',index:'requestor',sortable: true, width:100,editable:false, editrules:{required:true}, editoptions:{size:10}} ], postData: { }, height: 'auto', autowidth: true, rownumbers: true, pager: '#pager', viewrecords: true, sortorder: "asc", emptyrecords: "Empty records", loadonce: true, rowNum:20, ignoreCase: true, prmNames: { nd: null }, loadComplete: function() { }, jsonReader : { root: "rows", repeatitems: false, page:"page", total: "total", records: "records", cell: "cell", id: "id" } }); jQuery("#grid").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search: false, refresh:true}) .navButtonAdd('#pager',{caption:"Export All",buttonicon:"ui-icon-document",onClickButton: function(){window.open(excelUrl,'_self');},position:"last"}); jQuery("#grid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn",ignoreCase: true });

只有在我保留以下声明时,上面的网格才能正常工作(在更改rolelist组合框时正确刷新)。

jq("#grid").jqGrid('GridUnload');

如果我删除上面的语句并重新加载页面,而不是第一次正确加载网格,但之后如果我更改了我的角色列表组合框中的选项,它就无法刷新网格数据,也不会抛出任何错误。

我可以知道为什么我需要卸载网格进行刷新吗? 是不是有办法在不卸载网格的情况下刷新网格? 我是否遗漏了网格定义中的任何选项,这就是为什么网格重新加载不起作用?如果需要有关解决方案的上述问题的更多详细信息,请告诉我。

I am using jqgrid version 4.5.2. I have a role list combobox outside of the grid and on change of the options I need to reload the grid. Below is the defination of my grid.

var finalUrl=''; var queueStatus=jQuery('#queueStatus option:selected').val();

finalUrl= "http://localhost:8080/ui/paw/loadworkflowqueuedata.raws?selRole="+ selectedRole+"&"+queueStatus;

var queueStatus=jQuery('#queueStatus option:selected').val(); finalUrl= "http://localhost:8080/ui/paw/loadworkflowqueuedata.raws?timezone="+&selRole="+ selectedRole+"&"+queueStatus; jq("#grid").jqGrid('GridUnload'); jq("#grid").jqGrid({ url:finalUrl, ajaxGridOptions: {cache: false},//added the option to always reload the grid and not to cache the result. datatype: 'json', mtype: 'GET', colNames:[ 'Requestor Name'], colModel:[ {name:'requestor',index:'requestor',sortable: true, width:100,editable:false, editrules:{required:true}, editoptions:{size:10}} ], postData: { }, height: 'auto', autowidth: true, rownumbers: true, pager: '#pager', viewrecords: true, sortorder: "asc", emptyrecords: "Empty records", loadonce: true, rowNum:20, ignoreCase: true, prmNames: { nd: null }, loadComplete: function() { }, jsonReader : { root: "rows", repeatitems: false, page:"page", total: "total", records: "records", cell: "cell", id: "id" } }); jQuery("#grid").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search: false, refresh:true}) .navButtonAdd('#pager',{caption:"Export All",buttonicon:"ui-icon-document",onClickButton: function(){window.open(excelUrl,'_self');},position:"last"}); jQuery("#grid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn",ignoreCase: true });

The grid above works fine(refreshes properly on change of rolelist combobox) only if I keep the below statement.

jq("#grid").jqGrid('GridUnload');

If I remove the above statement and reload the page than for the first time grid loads properly but after that If I change the option in my role list combo box it is not able to refresh the grid data neither it is throwing any error.

May I know why I need to unload the grid for refresh? Isn't there a way through which I can refresh the grid with out unloading the grid? Did I miss any options in grid defination that is the reason why grid reload is not working?Please do let me know if need more details for the above question for the solution.

最满意答案

您使用loadonce: true选项非常有用,可以立即将所有服务器数据加载到客户端,然后使用客户端上的数据(分页,过滤等), 而无需与服务器进行任何通信 。 为此,jqGrid在第一次加载数据后将网格的datatype参数更改为"local" 。 因此,您需要触发reloadGrid事件之前将datatype参数的值重置为"json" 。

相应的代码就像

// create the initial grid jQuery("#grid").jqGrid({ ... url: finalUrl, datatype: 'json', loadonce: true, ... }); jQuery('#queueStatus').change(function () { jQuery("#grid").jqGrid("setGridParam", { datatype: "json", url: "basePartOfUrl?" + jQuery.param({ timezone: "blabla", selRole: jQuery('#queueStatus').val(); }) }).trigger("reloadGrid"); });

我使用上面的jQuery.param而不是直接构造字符串中的参数来使代码更正确。 或者,应该使用encodeURIComponent来构造附加到URL的参数值。 很明显,如果没有空格,没有特殊字符等,可以直接使用queueStatus ,但仍然建议使用encodeURIComponent或jQuery.param ,并使代码独立于字符串参数的值。

You use loadonce: true options which is very helpful to load all the server data to the client side at once and then working with the data on the client side (paging, filtering and so on) without any communication with the server. To do this jqGrid changes datatype parameter of the grid to "local" after the first loading of data. So you need to reset the value of datatype parameter back to "json" before trigger reloadGrid event.

The corresponding code will be like

// create the initial grid jQuery("#grid").jqGrid({ ... url: finalUrl, datatype: 'json', loadonce: true, ... }); jQuery('#queueStatus').change(function () { jQuery("#grid").jqGrid("setGridParam", { datatype: "json", url: "basePartOfUrl?" + jQuery.param({ timezone: "blabla", selRole: jQuery('#queueStatus').val(); }) }).trigger("reloadGrid"); });

I use above jQuery.param instead of direct construction of parameters in the string to make the code more correct. Alternatively one should use encodeURIComponent to construct the parameter values appended to URL. It's clear that one can use queueStatus directly if it has no space, no special characters and so on, but the usage of encodeURIComponent or jQuery.param is still recommended and make the code working independent from the value of the string parameter.

更多推荐

本文发布于:2023-04-27 11:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327116.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   不起作用   加载   JqGrid   grid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!