当使用jqGrid的,反正是有有recreateForm:真实的,但也缓存dataUrl? [英] When using jqgrid, is there anyway to have recreateForm: true but also cache dataUrl?
问题描述
我使用的jqGrid以下几列(简体)
I have the following columns using jqGrid (simplified)
{ name: "PMOPerson", index: "PMOPerson", width: 250, editable: true, edittype: "select", editoptions: { dataUrl: "/Person/GetSelectData" }, editrules: { required: false} },
{ name: "HeadDisplayName", index: "HeadDisplayName", width: 150, editable: false },
当我去编辑一行通过打开编辑对话框,它需要10秒钟进行填充PMOPerson下拉。这种情况即使我之前已经加载了一次,我以为是因为我有recreateForm:真正的下方
when i go to edit a row by bringing up the edit dialog, it take 10 seconds for the PMOPerson dropdown to be populated. This is the case even after i have already loaded it once before and i assume that is because i have recreateForm: true below
addButton({
caption: "",
title: "Edit Selected Team",
buttonicon: 'ui-icon-pencil',
onClickButton: function () {
var id = $("#grid").getGridParam("selrow");
if (id) {
jQuery("#grid").jqGrid('editGridRow', id,
{ url: '/OrganisationalUnit/Update', afterSubmit: function (response, postdata) {
var responseJson = $.parseJSON(response.responseText);
return HandleJqGridResponse(responseJson);
},
height: 380, width: "auto", recreateForm: true, closeAfterEdit: true,
closeOnEscape: true, reloadAfterSubmit: true
});
}
},
position: "second"
});
我试图找出是否有一种方法,我可以兼得recreateform:真实的,但也还是缓存在dataUrl的项目列表,以避免每一次我编辑的行要回服务器
I am trying to figure out if there is a way I can have both recreateform: true but still also cache the list of items in dataUrl to avoid going back to the server each time I edit a row.
推荐答案
我在这里回答了非常密切的问题 和< A HREF =http://stackoverflow.com/a/21884265/315935>此处。换句话说,你既可以使用HTTP标头的缓存选项或使用 editoptions.value
而不是 editoptions.dataUrl
的。
I answered on very close questions here and here. In other words you can either use caching options of HTTP header or to use editoptions.value
instead of editoptions.dataUrl
.
我答案并这两previous一(的this 和这)如何能够设置 editoptions.value
动态内 beforeProcessing
回调。一个需要从用于填充更多的信息网格(像从 editoptions.dataUrl
返回的数据的数据)服务器扩展响应。在我看来,由网格的重装实现 editoptions.dataUrl
数据缓存和刷新数据之间的最佳仲裁协议。人们可以犹抱缓存在服务器端 editoptions.dataUrl
数据的 的
I described in the answer and this two previous one (this and this) how one can set editoptions.value
dynamically inside of beforeProcessing
callback. One need extend the responses from the server used to fill the grid with additional information (with the data like the data returned from editoptions.dataUrl
). In my opinion it implements the best compromis between caching of editoptions.dataUrl
data and refreshing of the data by reloading of the grid. One can still hold cached editoptions.dataUrl
data on the server side.
或者我们可以使用更简单的办法,其中一个品牌的手动的网格的建立,一个可以设置后,Ajax请求 editoptions.dataUrl
一次 editoptions.value
里面的成功
(完成
)的回调Ajax请求。在code将有关以下
Alternatively one can use more simple way where one makes manual Ajax request to editoptions.dataUrl
once after creating of the grid and one can set editoptions.value
inside of success
(done
) callback of the Ajax request. The code will be about the following
// create grid
$("#grid").jqGrid({
colModel: [
{ name: "PMOPerson" },
...
],
...
});
// make separate asynchronous Ajax request to the server and set
// edittype: "select", editoptions: { value: ... }
setSelectOptionValues("/Person/GetSelectData", $("#grid"), "PMOPerson");
setSelectOptionValues
的$ C $,c取决于JSON数据,您可以用像/人/ GetSelectDataURL沟通的格式
。例如,如果服务器返回的只是字符串数组至极应该是文本和选项的值&LT;选择&GT;
则可能会是以下
The code of setSelectOptionValues
depends on the format of JSON data which you use to communicate with URL like "/Person/GetSelectData"
. For example if the server returns just array of strings wich should be the text and the value of options of the <select>
then the could could be the following
var setSelectOptionValues = function (getJsonUrl, myGrid, colModelColumnName) {
$.getJSON(
getJsonUrl,
function (data) {
var i, selectedOptions = '', datai, dn, colModelColumn;
for (i = 0; i < data.length; i += 1) {
if (i > 0) {
selectedOptions += ';';
}
else {
selectedOptions = "";
}
datai = data[i];
if (typeof datai === 'string') {
selectedOptions += datai;
selectedOptions += ':';
selectedOptions += datai;
}
}
myGrid.jqGrid("setColProp", colModelColumnName, {
edittype: "select",
editoptions: { value: selectedOptions }
});
}
);
};
editoptions.value
的设置将被做的异步 setSelectOptionValues
内部。因此,它可以是网格将在 editoptions.value
将被设置之前填补。在另一边 editoptions.value
将被修改的过程中使用的唯一的。从/人/ GetSelectData
的响应时间将通常足够快和值 editoptions.value
将设置的前的用户开始编辑。如果你想绝对相信你仍然可以持有 editoptions.dataUrl
。在这种情况下 editoptions.dataUrl
将被用来只有当用户尽快与响应的/人/ GetSelectData服务器
。您可以更改的显式调用
The setting of editoptions.value
will be done asynchronously inside of setSelectOptionValues
. So it can be that the grid will be filled before the editoptions.value
will be set. On the other side editoptions.value
will be used only during editing. The response time from "/Person/GetSelectData"
will be typically quick enough and the value editoptions.value
will be set before the user start editing. If you want be absolutely sure you can still hold editoptions.dataUrl
. In the case editoptions.dataUrl
will be used only if the user quickly as the server with responding on "/Person/GetSelectData"
. You can change explicit call of
setSelectOptionValues("/Person/GetSelectData", $("#grid"), "PMOPerson");
与得到 colModel
使用 getGridParam
,通过所有的循环 colModel
editoptions.dataUrl 。
with getting of colModel
using getGridParam
, the loop through all colModel
items and calling of setSelectOptionValues
for all items which has editoptions.dataUrl
.
最后一个方法的主要限制:不能使用格式中选择
(只 edittype:中选择
只)。如果您填写与IDS网格数据和 editoptions.value
或 formatoptions.value
提供的id以文本的映射,然后我会建议你使用与 beforeProcessing
回调第一种方法。
The main restriction of the last approach: you can't use formatter: "select"
(just edittype: "select"
only). If you fill grid data with ids and editoptions.value
or formatoptions.value
provides the mapping of ids to the texts then I would recommend you to use the first approach with beforeProcessing
callback.
这篇关于当使用jqGrid的,反正是有有recreateForm:真实的,但也缓存dataUrl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!