0
下面這段代碼不適用於本地數據的過濾器工具欄。JqGrid本地過濾器不工作
請幫我解決這個問題。 我是jqgrid的新手。我正在嘗試使我的網格在本地進行過濾。下面這段代碼是從小提琴中給出的例子中拿出來的。
我即將做同樣的事情,但會發生什麼,我在我的網格中有兩個過濾器。如果我選擇兩個過濾器,那麼只有網格才能正確過濾數據。但是,如果我只選擇一個過濾器,那麼網格不會獲得過濾器。 Eventhough第二過濾器值是「無濾波器」所有的
var serverResponse = [
{id: 10, label: 10, value: "Abc"},
{id: 20, label: 20, value: "Xyz"},
{id: 30, label: 30, value: "Abc"},
{id: 40, label: 40, value: "Xyz"},
{id: 50, label: 50, value: "Abc"},
{id: 60, label: 60, value: "Abc"},
{id: 70, label: 70, value: "Xyz"},
{id: 80, label: 90, value: "Abc"},
{id: 90, label: 10, value: "Xyz"},
{id: 100, label: 20, value: "Abc"},
{id: 110, label: 10, value: "Abc"},
{id: 120, label: 30, value: "Xyz"},
{id: 130, label: 10, value: "Abc"},
{id: 140, label: 60, value: "Xyz"},
{id: 150, label: 10, value: "Abc"}
];
$("#grid").jqGrid({
url: "/echo/json/", // use JSFiddle echo service
postData: {
json: JSON.stringify(serverResponse) // needed for JSFiddle echo service
},
mtype: "POST", // needed for JSFiddle echo service
datatype: "json",
colNames: ["Label", "Value"],
colModel: [
{name: "label", width: 70, template: "integer" },
{name: "value", width: 200 }
],
loadonce: true,
pager: true,
rowNum: 10,
rowList: [5, 10, "10000:All"],
iconSet: "fontAwesome",
cmTemplate: { autoResizable: true },
shrinkToFit: false,
autoResizing: { compact: true },
beforeProcessing: function (data) {
var labelMap = {}, valueMap = {}, i, item, labels = ":All", values = [], $self = $(this);
for (i = 0; i < data.length; i++) {
item = data[i];
if (!labelMap[item.label]) {
labelMap[item.label] = true;
labels += ";" + item.label + ":" + item.label;
}
if (!valueMap[item.value]) {
valueMap[item.value] = true;
values.push(item.value);
}
}
$self.jqGrid("setColProp", "label", {
stype: "select",
searchoptions: {
value: labels,
sopt: ["eq"]
}
});
$self.jqGrid("setColProp", "value", {
stype: "select",
searchoptions: {
value: values,
sopt: ["eq"]
}
});
// one should use stringResult:true option additionally because
// datatype: "json" at the moment, but one need use local filtreing later
$self.jqGrid("filterToolbar", {stringResult: true });
}
});