jQuery 使用不同的表数据重新加载已加载的 jqGrid
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1297044/
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
reload a loaded jqGrid with a different table data
提问by Ron Harlev
I have a page that displays a table in two different modes. In each mode I have a different set of columns. I'm using jqGrid to display the table. When I try to load the table for the second time (with same or different columns for that matter) the table will not refresh the data.
我有一个以两种不同模式显示表格的页面。在每种模式中,我都有一组不同的列。我正在使用 jqGrid 来显示表格。当我第二次尝试加载表时(为此使用相同或不同的列),该表不会刷新数据。
Is there a different API to reload data? Or should I use some method to clear the table first?
是否有不同的 API 来重新加载数据?或者我应该先使用某种方法来清除表格?
回答by mattmac
I ran into this same problem today. I use jqGrid to display search results from parameters specified in one or more form fields. I've got a click event on the search button and a keydown event on the fields themselves to capture the return key. Both events call a function that serializes the form and creates the initial jqGrid.
我今天遇到了同样的问题。我使用 jqGrid 显示一个或多个表单字段中指定参数的搜索结果。我在搜索按钮上有一个点击事件,在字段上有一个 keydown 事件来捕获返回键。这两个事件都调用一个函数来序列化表单并创建初始 jqGrid。
In the initial grid I have the option to call the function reloadEvents when the gridCompletes:
在初始网格中,我可以选择在 gridCompletes 时调用函数 reloadEvents:
gridComplete: reloadEvents
In the reloadEvents function I have:
在 reloadEvents 函数中,我有:
$("#frmSearch").bind("keydown", function(e) {
if (e.keyCode == 13) {
$('#searchList').setGridParam({url:'/model/actSearch.cfm?'+$('#frmSearch').serialize()});
$('#searchList').trigger("reloadGrid");
}
});
$('#btnSearch').click(function(){
$('#searchList').setGridParam({url:'/model/actSearch.cfm?'+$('#frmSearch').serialize()});
$('#searchList').trigger("reloadGrid");
});
If you're loading your data in your grid a different way you can use setGridParam to change whatever you need. The reloadGrid method is what should refresh your data based on the params you change.
如果您以不同的方式在网格中加载数据,您可以使用 setGridParam 来更改您需要的任何内容。reloadGrid 方法应该根据您更改的参数刷新您的数据。
回答by Ron Harlev
using the method "GridUnload" will unload the grid and leave the original HTML table. Next call to create the grid will start from scratch with any given schema
使用方法“GridUnload”将卸载网格并保留原始 HTML 表格。下一次创建网格的调用将使用任何给定的模式从头开始