我已經創建了一個基於此 example的過濾器工具欄。我有一個奇怪的問題;這僅適用於設置了螢火蟲斷點時,否則,下拉菜單僅顯示「全部」。網格設置爲數據類型:'json',loadonce:true。還有一點;這個網格也有一個子網格。任何想法如何讓這個工作?我宣佈了網後Jqgrid搜索工具欄過濾器與Json的唯一下拉列表
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"
});
任何建議,不勝感激。 謝謝
請問您可以用jsfiddle重現您的問題,以便我們可以看一看。我已經創建了一個適合您的資源(css和js) - http://jsfiddle.net/yTX3P/1/不要忘記保存它。 –
@Martijn B我的代碼可在[鏈接](http://jsfiddle.net/yTX3P/4/embedded/result/) – Heather
您的示例不會重現該問題。沒有可用的數據。我無法以這種方式幫助你。你可以嘗試的是從getUniqueNames方法返回uniqueTexts的斷點,並檢查哪些值被返回。如果這是空的,你必須關注getUniqueNames方法。 –