3 回答

TA貢獻1828條經(jīng)驗 獲得超3個贊
我也有類似情況。感謝Oleg在上面的出色示例,它幾乎解決了問題。我需要做一點改進。我的網(wǎng)格是一個有負載的網(wǎng)格,大約有40行,每頁10條。上面使用的getCol方法僅返回當前頁面的列值。但是我想用整個數(shù)據(jù)集中的唯一值填充過濾器。因此,對函數(shù)getUniqueNames進行了一些修改:
var getUniqueNames = function(columnName) {
// Maybe this line could be moved outside the function
// If the data is really huge then the entire segregation could
// be done in a single loop storing each unique column
// in a map of columnNames -> unique values
var data = grid.jqGrid('getGridParam', 'data');
var uniqueTexts = [], text, textsMap = {}, i;
for (i = 0; i < data.length; i++) {
text = data[i][columnName];
if (text !== undefined && textsMap[text] === undefined) {
// to test whether the texts is unique we place it in the map.
textsMap[text] = true;
uniqueTexts.push(text);
}
}
// Object.keys(textsMap); Does not work with IE8:
return uniqueTexts;
}

TA貢獻1811條經(jīng)驗 獲得超6個贊
我只是自己做的。感覺有點像駭客,但確實有效!
創(chuàng)建了一個新的“ navButtonAdd”,并為“標題”添加了用于下拉菜單的html代碼。
onclickButton函數(shù)不包含任何內(nèi)容。
然后,我創(chuàng)建了一個onchange函數(shù)來處理網(wǎng)格的重新加載(值更改時)。
$('#myGrid').jqGrid('navButtonAdd', '#myGrid_toppager', {
caption: "<select id='gridFilter' onchange='ChangeGridView()'><option>Inbox</option><option>Sent Messages</option></select>",
title: "Apply Filter",
onClickButton: function () {
}
});
function ChangeGridView() {
var gridViewFilter = $("#gridFilter").val();
$('#myGrid').setGridParam({ datatype: 'json', url: '../../Controller/ActionJSON', postData: { msgFilter: gridViewFilter } });
$('#myGrid').trigger("reloadGrid");
};
希望這可以幫助!
- 3 回答
- 0 關注
- 868 瀏覽
添加回答
舉報