Javascript 在加载新数据之前清除 jqGrid 不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5909359/
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
Clearing jqGrid before loading new data not working?
提问by Dieter
Hi there ^_^ I have the following problem:
你好^_^ 我有以下问题:
I have a partial view with a jqGrid on it...and I use bPopup
to display the partial view as a dialog.
我有一个带有 jqGrid 的局部视图……我bPopup
用来将局部视图显示为对话框。
Now there is a list of items on the side of the view. When clicking on an item...the dialog is to be displayed with the table displaying the data relating to that response...
现在在视图的一侧有一个项目列表。单击某个项目时...将显示对话框,其中包含显示与该响应相关的数据的表格...
Now the problem is that clicking on subsequent items; the data from the first item clicked is still showed...so I thought that simply calling
现在的问题是点击后续项目;点击的第一个项目的数据仍然显示......所以我认为只需调用
$("#ListDialogTable").jqGrid("clearGridData");
will clear the data and allow me to display the new data...but now when I try to show the dialog in subsequent clicks...only the table headers are shown...no data!
将清除数据并允许我显示新数据...但是现在当我尝试在后续单击中显示对话框时...只显示表标题...没有数据!
Any ideas and help on this appreciated :) D
对此有任何想法和帮助表示赞赏:) D
P.s. some code; the method below is called by method ShowListDialog
ps一些代码;下面的方法被方法调用ShowListDialog
function PopulateTable(model) {
$("#ListDialogTable").jqGrid("clearGridData");
$("#ListDialogTable").jqGrid({
jsonReader:
{
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: true,
cell: "cell",
id: "id"
},
colNames: model.columnN,
colModel: model.columnM,
datatype: "jsonstring",
datastr: model.columnD,
sortname: model.sortName,
sortorder: "asc",
autowidth: true,
celledit: false,
gridview: true,
height: "auto",
hoverrows: false,
shrinkToFit: true,
rowNum: 999,
viewrecords: true
});
}
回答by vishwas
You can unload the jqGrid
by using below method:
您可以jqGrid
使用以下方法卸载:
jQuery("#tableId").jqGrid("clearGridData");
jQuery("#tableId").jqGrid("clearGridData");
回答by Oleg
You don't posted how the element with id="ListDialogTable"
, which you use for the grid, are created. Will be it constructed dynamically or created once and be used many time? Moreover it is not clear whether the model.columnN
and model.columnM
can be changed between the calls or not. So I can only guess.
您没有发布id="ListDialogTable"
用于网格的带有 的元素是如何创建的。它是动态构造还是创建一次并使用多次?此外,还不清楚model.columnN
和是否model.columnM
可以在调用之间更改。所以我只能猜测。
Probably you need use GridUnloadmethod which allow you to recreatethe grid including all its elements including the column headers and the pager contain. The demofrom the answerdemonstrate how it works.
可能您需要使用GridUnload方法,该方法允许您重新创建网格,包括其所有元素,包括列标题和分页器包含的元素。演示从答案展示它是如何工作的。
回答by Yasser Shaikh
You can use jqgrid's GridUnloadmethod
你可以使用 jqgrid 的GridUnload方法
$("#tableId").jqGrid("GridUnload")
This will unload the entire grid and will allow you to load new data onto the grid.
这将卸载整个网格并允许您将新数据加载到网格上。
回答by Brane
I have same issues because i am using older version of jqGrid and this is my solution for this:
我有同样的问题,因为我使用的是旧版本的 jqGrid,这是我的解决方案:
jQuery("#grid").clearGridData(true).trigger("reloadGrid");
jQuery("#grid").clearGridData(true).trigger("reloadGrid");