问题描述
在我的jqGrid中,我使用multiselect参数,以便每行上都有一个复选框.网格显示一个列表,其中每一行都处于打开"状态.可以检查许多行,并且当单击从分包商处关闭故障"按钮时,所有被选中的条目都将被赋予新的状态已关闭".由于此网格仅显示打开"条目,因此将重新查询数据库,并且需要显示一个新的打开条目列表.为此,需要使用新数据重新加载网格.当前,reloadGrid无法正常工作,显示的数据与以前相同.
In my jqGrid I use the multiselect parameter so that there is a checkbox on each row.The grid shows a list where each row has an "Open" status. A number of rows may be checked and when the "Close Faults from Subcontractor" button is clicked, all the ticked entries will be assigned a new status of "closed".As this grid only displays "open" entries, the database is requeried and a new list of open entries needs to be displayed.To do this the grid needs to be reloaded with the new data.Currently the reloadGrid is not working, the same data is shown as before.
$(function () {
getDataForGrid(populateGrid);
});
var populateGrid = function (data) {
var grid = $("#grid");
grid.jqGrid({
data: data,
multiselect: true,
colNames: ["Category", "Description", "Opened", "Urgency", "Location"],
colModel: [
{ name: "category", index: "category", width: 200, align: "left" },
{ name: "description", index: "description", width: 200, align: "left" },
{
name: "dateOpened",
index: "dateOpened",
width: 100,
align: "left",
formatter: "date",
formatoptions: { newformat: "d-M-Y" }
},
{ name: "urgency", label: "urgency", width: 200, align: "left" },
{ name: "location", label: "location", width: 100, align: "left" }
],
//guiStyle: "bootstrap",
prmNames: { id: "faultId" },
localReader: { id: "faultId" },
cmTemplate: { autoResizable: true },
rowNum: 20,
pager: "#pager",
shrinkToFit: true,
rownumbers: true,
sortname: "category",
viewrecords: true
}).jqGrid("gridResize")
.navGrid("#pager", {
edit: false,
add: false,
del: false,
search: false,
refresh: false
}).navButtonAdd("#pager",
{
caption: "Close Faults from Subcontractor",
buttonicon: "ui-icon-circle-check",
position: "first",
title: "Blue Button",
onClickButton: function () {
var pdfFile = $("#documentName").val();
if (pdfFile === undefined || pdfFile === null || pdfFile.length === 0) {
errorValidationMessage("You must upload a Subcontractor's confirmation pdf first before closing faults");
return false;
}
var selRowIds = grid.jqGrid("getGridParam", "selarrrow");
if (selRowIds.length === 0) {
errorValidationMessage("You did not select any faults to close");
return false;
}
var contractSubcontractorId = GetHiddenField("sir-contract-subcontractor-id");
var documentName = pdfFile.replace(/\\/g, "/").replace(/.*\//, "");
var url = GetHiddenField("sir-close-faults-from-subcontractor-url");
var postData = JSON.stringify({ faultIds: selRowIds, contractSubcontractorId: contractSubcontractorId, documentName: documentName });
var callback = reloadGrid;
dataService.putData(url, postData, callback);
}
});
$("#divLoading").hide();
}
var getDataForGrid = function (callback) {
var url = GetHiddenField("sir-get-open-faults-list");
dataService.getList(url, callback);
}
var reloadGrid = function () {
showSuccessMessage("Selected Properties Closed");
getDataForGrid(reloadGridWithUpdatedData);
}
var reloadGridWithUpdatedData = function (data) {
var grid = $("#grid");
grid.jqGrid("setGridParam", { data: data });
grid.trigger("reloadGrid", data);
}
推荐答案
在我看来,您遇到问题的原因在于使用setGridParam
.仅当您更改不是数组的参数时,才应使用该方法.您当前的代码与新的data
合并(请参见 setGridParam
代码的主行,该代码调用 $.extend ).如果是数组,则应使用setGridParam
的第二个(overwrite
)参数:
It seems to me that the reason of your problem is in the usage of setGridParam
. The method should be worked only if you change parameters, which are not arrays. Your current code merges old data
with new one (see the main line of code of setGridParam
, which calls deep version of $.extend). In case of arrays you should use the second (overwrite
) parameter of setGridParam
:
var reloadGridWithUpdatedData = function (data) {
var grid = $("#grid");
grid.jqGrid("setGridParam", { data: data }, true);
grid.trigger("reloadGrid");
}
或根本不使用setGridParam
.方法getGridParam
为内部对象提供引用,该对象包含所有参数.它允许以非常简单的方式替换(覆盖)任何参数:
or just don't use setGridParam
at all. The method getGridParam
gives the reference to internal object, which holds all parameters. It allows to replace (overwrite) any parameter in very simple way:
var reloadGridWithUpdatedData = function (data) {
var grid = $("#grid"),
p = grid.jqGrid("getGridParam"); // get reference to all parameters
p.data = data; // replace data parameter
grid.trigger("reloadGrid");
}
这篇关于重新加载不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!