Jqgrid 搜索工具栏使用 Json 过滤唯一的下拉列表
我基于此 示例创建了一个过滤器工具栏 。我有一个奇怪的问题;这仅在我设置了萤火虫断点时才有效,否则,下拉列表仅显示“全部”。网格设置为 datatype:'json', loadonce:true。还有一点;该网格还有一个子网格。关于如何让它发挥作用有什么想法吗?
grid = $("#dealsgrid"),
getUniqueNames = function(columnName) {
var texts = grid.jqGrid('getCol', columnName);
var uniqueTexts = [];
var textsLength = grid.jqGrid('getGridParam','data');
var text, textsMap = {}, i;
for (i = 0; i < textsLength; i++) {
text = texts[i];
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);
}
}
return uniqueTexts;
},
buildSearchSelect = function(uniqueNames) {
var values = ":All";
$.each(uniqueNames, function() {
values += ";" + this + ":" + this;
});
return values;
},
setSearchSelect = function(columnName) {
grid.jqGrid(
'setColProp',
columnName,
{
stype : 'select',
searchoptions : {
value : buildSearchSelect(getUniqueNames(columnName)),
sopt : [ 'eq' ]
}
});
};
我在声明网格后,我的列模型如下所示:
colModel:[
{name:'CM',index:'CM', width:50,editable:false},
{name:'DealNo',index:'DealNo',width:75,editable:false,editoptions:{readonly:true, size:10},search:true, stype:'text', searchoptions: { sopt: ['eq']}},
{name:'KeyDate',index:'KeyDate',width:100, search:false, align:"right",formatter:'date'},
{name:'VendorNo',index:'VendorNo', width:75,search:true},
{name:'VendorName',index:'VendorName', width:100,search:true},
{name:'ItemQty',index:'ItemQty', width:75,search:false},{name:'StartDate',index:'StartDate',width:100,align:"right",formatter:'date',search:false},
{name:'EndDate',index:'EndDate',width:100, align:"right",formatter:'date',search:false},
{name:'ActiveStartDate',index:'ActiveStartDate',width:100, align:"right",formatter:'date',search:false, sorttype:"date", editable:true,editoptions:{size:10}}, {name:'ActiveEndDate',index:'ActiveEndDate',width:100,align:"right",formatter:'date',search:false, sorttype:"date",editable:true,editoptions:{size:10}},
{name:'DealType',index:'DealType', width:75,search:false}
],
最后,我调用创建filterToolBar并填充下拉列表
setSearchSelect('CM');
grid.jqGrid('setColProp', 'Name', {
searchoptions : {
sopt : [ 'cn' ],
dataInit : function(elem) {
$(elem).autocomplete({
source : getUniqueNames('Name'),
delay : 0,
minLength : 0
});
}
}
});
grid.jqGrid('filterToolbar', {
stringResult : true,
searchOnEnter : true,
defaultSearch : "eq"
});
任何建议将不胜感激。 谢谢
I have created a filter toolbar based on this example. I have an odd problem; this only works when I have firebug breakpoints set, otherwise, the dropdown only displays 'All'. The grid is set with datatype:'json', loadonce:true. One more point; this grid also has a sub grid. Any idea on how to get this working?
grid = $("#dealsgrid"),
getUniqueNames = function(columnName) {
var texts = grid.jqGrid('getCol', columnName);
var uniqueTexts = [];
var textsLength = grid.jqGrid('getGridParam','data');
var text, textsMap = {}, i;
for (i = 0; i < textsLength; i++) {
text = texts[i];
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);
}
}
return uniqueTexts;
},
buildSearchSelect = function(uniqueNames) {
var values = ":All";
$.each(uniqueNames, function() {
values += ";" + this + ":" + this;
});
return values;
},
setSearchSelect = function(columnName) {
grid.jqGrid(
'setColProp',
columnName,
{
stype : 'select',
searchoptions : {
value : buildSearchSelect(getUniqueNames(columnName)),
sopt : [ 'eq' ]
}
});
};
I after declaring the grid, my column model looks like this:
colModel:[
{name:'CM',index:'CM', width:50,editable:false},
{name:'DealNo',index:'DealNo',width:75,editable:false,editoptions:{readonly:true, size:10},search:true, stype:'text', searchoptions: { sopt: ['eq']}},
{name:'KeyDate',index:'KeyDate',width:100, search:false, align:"right",formatter:'date'},
{name:'VendorNo',index:'VendorNo', width:75,search:true},
{name:'VendorName',index:'VendorName', width:100,search:true},
{name:'ItemQty',index:'ItemQty', width:75,search:false},{name:'StartDate',index:'StartDate',width:100,align:"right",formatter:'date',search:false},
{name:'EndDate',index:'EndDate',width:100, align:"right",formatter:'date',search:false},
{name:'ActiveStartDate',index:'ActiveStartDate',width:100, align:"right",formatter:'date',search:false, sorttype:"date", editable:true,editoptions:{size:10}}, {name:'ActiveEndDate',index:'ActiveEndDate',width:100,align:"right",formatter:'date',search:false, sorttype:"date",editable:true,editoptions:{size:10}},
{name:'DealType',index:'DealType', width:75,search:false}
],
and finally, my call to create the filterToolBar and populate the dropdown
setSearchSelect('CM');
grid.jqGrid('setColProp', 'Name', {
searchoptions : {
sopt : [ 'cn' ],
dataInit : function(elem) {
$(elem).autocomplete({
source : getUniqueNames('Name'),
delay : 0,
minLength : 0
});
}
}
});
grid.jqGrid('filterToolbar', {
stringResult : true,
searchOnEnter : true,
defaultSearch : "eq"
});
Any suggestions would be greatly appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在删除了我的旧答案,我们知道您的函数正在返回某些内容(如果您在其上放置了断点)。难道是你的网格在调用 getUniqueNames 之前还没有加载数据?这说明,如果在其上放置断点,则在调用 getUniqueNames 之前它有更多时间加载数据。
因此,如果您在 gridComplete 中调用 setSearchSelect 或者甚至在 loadComplete 中调用,应该没问题。也许您甚至必须将网格的 async 属性设置为 false。我需要用我自己的代码进行检查,所以我可以为您提供一个示例。我早上第一件事就是做这件事。同时您可以根据上述信息自行尝试进行一些调整。
Removed my old answer now we know that your function is returning something (if you put a breakpoint on it). Could it be that your grid has not yet loaded the data before getUniqueNames is called? This explains that if you put a breakpoint on it, it has more time to load the data before the getUniqueNames is called.
So if you call the setSearchSelect in the gridComplete or maybe even the loadComplete it should be ok. Maybe you even have to set the async property of the grid to false. I would need to check that with my own code, so I could provide you with a example. I will do this first thing in the morning. In the mean time you could try it yourself by doing some adjustments based on the info above.