Code:
Ext.onReady(function() {
var data = [
['001', '张三', 'zhangsan', '男', 24],
['002', '李四', 'lisi', '男', 23],
['003', '刘秀', 'liusiu', '女', 20]
];
var store = new Ext.data.SimpleStore ({
fields: [
{name: 'id'},
{name: 'chineseName'},
{name: 'englishName'},
{name: 'sex'},
{name: 'age', type: 'int'}
]
});
store.loadData(data);
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: 'ID号', width: 80, sortable: true, dataIndex: 'id'},
{header: '中文名', width: 100, sortable: true, dataIndex: 'chineseName'},
{header: '英文名', width: 100, sortable: true, dataIndex: 'englishName'},
{header: '性别', width: 100, sortable: true, dataIndex: 'sex'},
{header: '年龄', width: 100, sortable: true, dataIndex: 'age'}
],
stripeRows: true,
autoExpandColumn: 'id',
height:150,
width:480,
title:'用户列表'
});
grid.render('div_grid');
grid.getSelectionModel().selectFirstRow();
});
我在Ext.grid.GridPanel里加了autoExpandColumn属性,但是又没有设置id给它,如:
{header: 'ID号', width: 80, sortable: true, dataIndex: 'id'}
应该改成为:
{id: 'id', header: 'ID号', width: 80, sortable: true, dataIndex: 'id'},
这样就可以解决问题了。