问题描述
我们在 loadonce
设置为 true 的网格上使用 jqGrid 导航器重新加载按钮.
We use the jqGrid navigator reload button on a grid with loadonce
set to true.
reload 按钮目前不会返回服务器获取数据 - 我们如何让 reload 去服务器获取最新数据?
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?
我相信我们可以使用 beforeRefresh
回调将网格 data
设置为 json
而不是 local
但我什至不清楚如何配置 beforeRefresh
方法 - 我不太了解文档.
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.
推荐答案
你不是唯一有问题的人.我之前回答过同样的问题.要从服务器重新加载网格内容,您应该将 datatype
参数重置为原始值json"或xml",然后刷新网格.例如
You are not the only person which has the problem. I answerd to the same question before. 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
jQuery("#list").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
更新:调用 beforeRefresh 事件处理程序,您可以执行以下操作
UPDATED: To call the line inside of beforeRefresh event handler you can do following
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. Here if you click on the refresh button you can see live how the code work.
更新 2:Free jqGrid 支持一些新选项.reloadGrid
事件支持 fromServer: true
参数,该参数可用于强制从服务器重新加载数据,navGrid
支持 reloadGridOptions
选项可用于指定单击刷新按钮时使用的 reloadGrid
选项.所以上面的代码可以是
UPDATED 2: Free jqGrid supports 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
$("#list").jqGrid("navGrid", {
edit: false,
add: false,
del: false,
search: false,
reloadGridOptions: { fromServer: true }
});
顺便说一句,可以使用 jqGrid 的 navOptions
选项来指定 navGrid
的默认选项(参见 wiki 文章).它允许编写类似的代码
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
$("#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");
这篇关于如何让 jqGrid 重新加载到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!