jQuery 如何让jqGrid重新加载到服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3772334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get jqGrid reload to go to server?
提问by Marcus Leon
We use the jqGrid navigator reload button on a grid with loadonce
set to true.
我们在loadonce
设置为 true的网格上使用 jqGrid 导航器重新加载按钮。
The reload button currently does NOT go back to the server to get the data - how can we get the reload to go to the server to get the latest data?
重新加载按钮当前不会返回服务器获取数据 - 我们如何才能重新加载到服务器以获取最新数据?
I believe we can use the beforeRefresh
callback to set the grid data
to json
instead of local
but I'm not clear how to even configure the beforeRefresh
method - I don't really understand the docs.
我相信我们可以使用beforeRefresh
回调将网格设置data
为json
而不是,local
但我什至不清楚如何配置该beforeRefresh
方法 - 我不太了解文档。
回答by Oleg
You are not the only person which has the problem. I answerd to the same questionbefore. To reload the grid content from the server you should reset the datatype
parameter to original value "json" or "xml" and then refresh the grid. For example
你不是唯一有问题的人。我之前回答过同样的问题。要从服务器重新加载网格内容,您应该将datatype
参数重置为原始值“json”或“xml”,然后刷新网格。例如
jQuery("#list").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
UPDATED: To call the line inside of beforeRefreshevent handler you can do following
更新:要调用beforeRefresh事件处理程序中的行,您可以执行以下操作
jQuery("#list").jqGrid('navGrid','#pager',
{ edit:false,view:false,add:false,del:false,search:false,
beforeRefresh: function(){
alert('In beforeRefresh');
grid.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
}
});
I modified an example from am old question. Hereif you click on the refresh button you can see live how the code work.
我修改了一个老问题的例子。在这里,如果您单击刷新按钮,您可以实时查看代码的工作方式。
UPDATED 2: Free jqGridsupports some new options. reloadGrid
event supports fromServer: true
parameter which can be used to force reloading of data from the server and navGrid
supports reloadGridOptions
option which can be used to specify the options of reloadGrid
used on click on Refresh button. So the above code could be
更新 2:免费 jqGrid支持一些新选项。reloadGrid
事件支持fromServer: true
可用于强制从服务器重新加载数据的参数,并navGrid
支持reloadGridOptions
可用于指定reloadGrid
单击刷新按钮时使用的选项的选项。所以上面的代码可以是
$("#list").jqGrid("navGrid", {
edit: false,
add: false,
del: false,
search: false,
reloadGridOptions: { fromServer: true }
});
By the way one can use navOptions
option of jqGrid to specify default options of navGrid
(see the wiki article). It allows to write the code something like
顺便说一句,可以使用navOptions
jqGrid 的选项来指定navGrid
(请参阅维基文章)的默认选项。它允许编写类似的代码
$("#link").jqGrid({
// all typical jqGrid parameters
datatype: "json", // or "xml"
loadonce: true,
pager: true, // no empty div for page is required
navOptions: {
edit: false,
add: false,
del: false,
search: false,
reloadGridOptions: { fromServer: true }
}
}).jqGrid("navGrid");
回答by Lihong Wei
I have tried the following config and it works.
我已经尝试了以下配置并且它有效。
<script type="text/javascript">
jQuery(function() {
jq("#YOUR-GRID-ID").jqGrid({
...
loadonce: true,
...
});
jQuery("#refresh_YOUR-GRID-ID").click(function(){
jQuery("#YOUR-GRID-ID").setGridParam({datatype: 'json'});
jQuery("#YOUR-GRID-ID").trigger("reloadGrid");
});
});
</script>