今天用sample中的Customer Search Field 结合 GridPanel 做一个查找功能,两者用的数据是同一个GroupingStore,通过proxy 从服务器取数据。服务器返回的是数组形式,但我发现当点下搜索按钮就报错:"F has no property"或"SP has no property",用Firebug 也找不到原因,就想问一下,会不会是因为远程返回的数据必须用json或xml格式呢?
[b]问题补充:[/b]
谢谢jayxu的回答,我刚才仔细测试了一下(顺便说一下,今天用IE8的Developer Tools),终于找到了问题,就是:groupField 指定的栏位,在columns -- header 中一定要写dataIndex。我debug到ext-all-debug里发现,如果不写的话,会在findColumnIndex时出错。
[b]问题补充:[/b]
漏了说,服务器返回数组也是可以的。因为我这里不需要翻页,所以用Array简单一点。
[b]问题补充:[/b]
Ext.onReady(function(){
Ext.QuickTips.init();
var xg = Ext.grid;
var ds = new Ext.data.GroupingStore({
url: 'voice/searchPhone.do',
reader: new Ext.data.ArrayReader({}, [
{name: 'category'},
{name: 'phoneno'},
{name: 'name'}
]),
sortInfo:{field: 'phoneno', direction: "ASC"},
groupField:'category'
});
var grid = new xg.GridPanel({
store: ds,
columns: [
{header: "phoneno", width: 20, dataIndex:"phoneno"},
{header: "name", width: 20, dataIndex:"name"},
{header: "category", dataIndex: "category", hidden: true}
],
view: new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
//frame:true,
hideHeaders: true,
width: 400,
height: 300,
iconCls: 'icon-grid'
//renderTo: document.body
});
//ds.load();
/**
* Dial window
*/
var win = new Ext.Window({
id:'hello-win',
title:'Search phone-no and people',
layout:'fit',
width:450,
height:350,
closeAction:'hide',
plain: true,
items: grid,
tbar: [
'Search: ', ' ',
new Ext.app.SearchField({
id: 'searchField',
store: ds,
width:280
}),
new Ext.Button({
text: 'Dial',
handler: dial
})
]
});
});