Ned帮助让jqgrid使用typeahead和本地数据,而不是ajax调用。从jgrid网站(http://www.guriddo.net/demo/bootstrap/:搜索工具栏:搜索控件(日期选择器,自动完成,下拉列表,复选框,自定义等)中获取示例:
label : "Ship Name",
name: 'ShipName',
width: 150,
searchoptions: {
// dataInit is the client-side event that fires upon initializing the toolbar search field for a column
// use it to place a third party control to customize the toolbar
dataInit: function (element) {
$(element).attr("autocomplete","off").typeahead({
appendTo : "body",
source: function(query, proxy) {
$.ajax({
url: 'http://trirand.com/blog/phpjqgrid/examples/jsonp/autocompletepbs.php?callback=?&acelem=ShipName',
dataType: "jsonp",
data: {term: query},
success : proxy
});
}
});
},
sopt : ['cn']
}
我正在尝试使用相同的逻辑但使用本地数据:
var namelist = ["name 1","name 2", bla bla bla...,"name x"]
nameGrid.jqGrid({
url : '/ajaxx/ajax.getList.php',
mtype : "POST",
datatype : "json",
page : 1,
colNames : ['ID', 'program Name', 'program Group'],
colModel : [
{ name: 'ID',key: true, width: 75, search:false, hidden:false},
{ name: 'Name',width: 200, seacrh:true, stype:'text',
cellattr: function (rowId, tv, rawObject, cm, rdata) {
return 'style="white-space: normal;'
},
searchoptions: {
dataInit: function (element) {
$(element).attr("autocomplete","off").typeahead({
appendTo : "body",
source: namelist,
});
},
sopt : ['cn']
}
}
],
//rest of options
.........
});
当我开始输入网格的搜索字段时,它只显示一个字母,只显示它匹配的第一个字母。例如,假设我有[阿兰,詹姆斯,理查德]作为名字,如果我开始寻找阿兰,我键入“a”,它将显示所有行只有“a”,如果我键入第二个字母,如“l”,一切都将消失,我回到一个普通的文本框,里面有两个字母“al”