[英]Dynamically populate Jqgrid drop-down filter
我已經修改了現有的Javascript函數,以允許我填充多個Jqgrid下拉過濾器。 代碼是:
jQuery("#jQGridDemo").jqGrid({
url: 'http://localhost:58404/JQGridHandler.ashx',
datatype: "json",
colNames: ['Property ID', 'Property Ref', 'Short Address', 'Scheme Code', 'Scheme Name'],
colModel: [
{ name: 'PropertyID', index: 'PropertyID', width: 70, align: "left", stype: 'text', sortable: true},
{ name: 'PropertyRef', index: 'PropertyRef', width: 75, align: "left", stype: 'text', sortable: true},
{ name: 'ShortAddress', index: 'ShortAddress', width: 200, align: "center", sortable: true},
{ name: 'SchemeCode', index: 'SchemeCode', width: 80, align: "center", sortable: true },
{ name: 'SchemeName', index: 'SchemeName', width: 80, align: "center", sortable: true },
{name: 'PropertyType',width: 80},
],
beforeProcessing: function (data) {
getDropDownValues(data, "PropertyType")
}
.jqGrid('destroyFilterToolbar')
.jqGrid('filterToolbar', {
stringResult: true,
searchOnEnter: false,
defaultSearch: "cn"
});
}
function getDropDownValues(data, columnName) {
var propertyMap = {}, propertyValues = ":All", rows = data, i, symbol;
for (i = 0; i < rows.length; i++) {
symbol = rows[i].columnName;
if (!propertyMap.hasOwnProperty(symbol)) {
propertyMap[symbol] = 1;
propertyValues += ";" + symbol + ":" + symbol;
}
}
$(this).jqGrid("setColProp", 'columnName', {
stype: "select",
searchoptions: {
value: propertyValues
}
})
}
但是,即使提供的列名(“ PropertyType”)存在,也不會在Json數據中找到。 原始函數具有明確提到的列名,並且可以工作:
symbol = rows[i].PropertyType;
有人知道我應該如何引用作為變量而不是被明確提及的列名嗎?
樣本數據:
[{"PropertyID":1,"PropertyRef":"1","ShortAddress":"99 ROCK LANE,BODMIN,PL91 1NR","SchemeCode":"700000","SchemeName":"LODMIN","PropertyType":"HOU"}
謝謝
在對象中將字符串參數作為屬性傳遞的方式將不起作用。
在運行時,這等效於:
符號=行[i]。“ PropertyType”
這是不正確的。
幸運的是,您可以傳遞它,因為它是數組元素。 像這樣
symbol = rows [i] [columnName];
在運行時將產生
symbol = rows [i] [“ PropertyType”];
哪個是對的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.