jqgrid是否可以在工具栏过滤器字段中支持下拉菜单

我正在使用jqgrid和工具栏过滤器。默认情况下,它只是给您一个文本框,用于输入数据。它是否支持下拉选择组合框,我可以在其中提供一个值列表以供选择以筛选?



MYYA
浏览 847回答 3
3回答

子衿沉夜

我也有类似情况。感谢Oleg在上面的出色示例,它几乎解决了问题。我需要做一点改进。我的网格是一个有负载的网格,大约有40行,每页10条。上面使用的getCol方法仅返回当前页面的列值。但是我想用整个数据集中的唯一值填充过滤器。因此,对函数getUniqueNames进行了一些修改:var getUniqueNames = function(columnName) {// Maybe this line could be moved outside the function&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 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 valuesvar data = grid.jqGrid('getGridParam', 'data');var uniqueTexts = [], text, textsMap = {}, i;for (i = 0; i < data.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;text = data[i][columnName];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (text !== undefined && textsMap[text] === undefined) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// to test whether the texts is unique we place it in the map.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;textsMap[text] = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uniqueTexts.push(text);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Object.keys(textsMap); Does not work with IE8:&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return uniqueTexts;}

杨魅力

我只是自己做的。感觉有点像骇客,但确实有效!创建了一个新的“ navButtonAdd”,并为“标题”添加了用于下拉菜单的html代码。onclickButton函数不包含任何内容。然后,我创建了一个onchange函数来处理网格的重新加载(值更改时)。&nbsp; &nbsp; $('#myGrid').jqGrid('navButtonAdd', '#myGrid_toppager', {&nbsp; &nbsp; &nbsp; &nbsp; caption: "<select id='gridFilter' onchange='ChangeGridView()'><option>Inbox</option><option>Sent Messages</option></select>",&nbsp; &nbsp; &nbsp; &nbsp; title: "Apply Filter",&nbsp; &nbsp; &nbsp; &nbsp; onClickButton: function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp; function ChangeGridView() {&nbsp; &nbsp; &nbsp; &nbsp; var gridViewFilter = $("#gridFilter").val();&nbsp; &nbsp; &nbsp; &nbsp; $('#myGrid').setGridParam({ datatype: 'json', url: '../../Controller/ActionJSON', postData: { msgFilter: gridViewFilter } });&nbsp; &nbsp; &nbsp; &nbsp; $('#myGrid').trigger("reloadGrid");&nbsp;&nbsp; &nbsp; };&nbsp;希望这可以帮助!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery