【发布时间】:2019-04-25 20:28:26
【问题描述】:
我有一个 Jqgrid 如下:
jQuery("#jQGridDemo").jqGrid({
url: 'http://localhost:58404/JQGridHandler.ashx',
colNames: ['Property ID', 'Property Ref', 'Short Address', 'Scheme Code', 'Scheme Name', 'Property Type', 'Tenure Type', 'Status', 'Management Cost','Rent Charge Month','SC Charge Month'],
colModel: [
{ name: 'PropertyID', index: 'PropertyID', width: 70, align: "left", stype: 'text', sortable: true},
{name: 'PropertyType',width: 80},
{ name: 'TenureType', index: 'TenureType', width: 80, align: "center", sortable: true },
{ name: 'Status', index: 'Status', width: 75, align: "center", sortable: true },
],
网格工作并使用从 URL 返回的 Json 进行填充。 但是,我正在尝试在 PropertyType 列上实现一个动态填充的下拉过滤器,并且一直在这里查看 Oleg 的答案:How to add dynamic filter drop down using Jqgrid?
因此我添加了一个“beforeProcessing”功能:
beforeProcessing: function (data) {
var propertyMap = {}, propertyValues = ":All", rows = data.rows, i, symbol;
for (i = 0; i < rows.length; i++) {
symbol = rows[i].Symbol;
if (!propertyMap.hasOwnProperty(symbol)) {
propertyMap[symbol] = 1;
propertyValues += ";" + symbol + ":" + symbol;
}
}
$(this).jqGrid("setColProp", 'PropertyType', {
stype: "select",
searchoptions: {
value: propertyValues
}
}).jqGrid('destroyFilterToolbar')
.jqGrid('filterToolbar', {
stringResult: true,
searchOnEnter: false,
defaultSearch: "cn"
});
},
我的问题是,如何将URL返回的数据传递给“beforeProcessing:函数(数据)” -
任何帮助将不胜感激。
【问题讨论】:
-
已经通过了。不确定我是否理解。在将数据插入网格之前,将来自服务器的数据传递给该事件。关于此事件,不同的 jqGrid 版本也存在一些差异 - 实际上使用了哪个版本的 jqGrid - Guriddo jqGrid、free-jqGrid 或 jqGrid
-
我使用的是 4.5.1 版本。调试器告诉我 rows 为空。所以我假设数据在插入网格之前没有被传递给函数。
-
你的数据类型是什么?如果数据类型是本地的,则不会在 4.5 版中传递。对于此版本,仅当数据类型为 json 或 xml 时才传递数据。该问题在 Guriddo jqGrid 版本中不存在。
-
我的数据类型是 Json。
-
尝试 console.log 数据。根据 jsonReader , data.rows 属性可能不存在。就在 rows = data.rows 之前。仅制作数据的 console.log
标签: filter drop-down-menu jqgrid