ext grid 如何实现默认选中行?
westPDStore.load({callback:function(r,options,success){if(success){westPDGrid.getSele...
westPDStore.load(
{callback: function(r, options, success){
if(success){
westPDGrid.getSelectionModel().selectFirstRow(0);
alert( westPDGrid.getSelectionModel().selectFirstRow(0)) ;
}else{
Ext.Msg.alert('操作','失败!');
} }}}怎么这样也不能实现默认选中行
var westPDData=[ ['Categories'], ['Process Definitions'], ['Process Instances'], ['Activity Instances'] ];
var westPDColumn=new Ext.grid.ColumnModel([
{dataIndex:'description',width:50, name:'description' } ]);
var westPDStore=new Ext.data.Store({ proxy:new Ext.data.MemoryProxy(westPDData),
reader:new Ext.data.ArrayReader({},[ {name:'description'}]) });
westPDGrid=new Ext.grid.GridPanel({
id:'wesGrid',
loadMask:true,
store:westPDStore,
cm:westPDColumn,
height:124,
autoHeight: true,
viewConfig:{
forceFit:true,
scrollOffset: 0
}
}) ;
westPDStore.load(); 展开
{callback: function(r, options, success){
if(success){
westPDGrid.getSelectionModel().selectFirstRow(0);
alert( westPDGrid.getSelectionModel().selectFirstRow(0)) ;
}else{
Ext.Msg.alert('操作','失败!');
} }}}怎么这样也不能实现默认选中行
var westPDData=[ ['Categories'], ['Process Definitions'], ['Process Instances'], ['Activity Instances'] ];
var westPDColumn=new Ext.grid.ColumnModel([
{dataIndex:'description',width:50, name:'description' } ]);
var westPDStore=new Ext.data.Store({ proxy:new Ext.data.MemoryProxy(westPDData),
reader:new Ext.data.ArrayReader({},[ {name:'description'}]) });
westPDGrid=new Ext.grid.GridPanel({
id:'wesGrid',
loadMask:true,
store:westPDStore,
cm:westPDColumn,
height:124,
autoHeight: true,
viewConfig:{
forceFit:true,
scrollOffset: 0
}
}) ;
westPDStore.load(); 展开
2个回答
展开全部
写一个store的load事件,如果store.getCount()>0 采用grid 选中第一行的方法选中第一行就行了
store.on('load',function(){
if(store.getCount()>0){
grid.getSelectionModel().selectFirstRow();
}
})
store.on('load',function(){
if(store.getCount()>0){
grid.getSelectionModel().selectFirstRow();
}
})
追问
这样也不能实现。他没有选中第一行。
追答
Ext.onReady(function(){
var grid;
var data = [
['01','123','a1','e1'],
['02','123','a2','e2'],
['03','123','a3','e3'],
['04','123','a4','e4'],
['05','123','a5','e5'],
['06','123','a6','e6'],
['07','123','a7','e7'],
['08','123','a8','e8'],
['09','123','a9','e9'],
['10','123','a10','e10']
];
var ds = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy(data),
reader: new Ext.data.ArrayReader({
fields:[
{name:'id'},
{name:'password'},
{name:'name'},
{name:'email'}
]
}),
listeners : {
'load' :function(){
grid.getSelectionModel().selectFirstRow();
}
}
});
// create the Grid
grid = new Ext.grid.GridPanel({
store: ds,
columns: [
{header:'编号',dataIndex:'id'},
{header:'密码',dataIndex:'password'},
{header:'姓名',dataIndex:'name'},
{header:'邮箱',dataIndex:'email'}
],
width:600,
title:'Sliding Pager',
autoHeight:true,
listeners : {
'render' :function(){
grid.getSelectionModel().selectFirstRow();
}
}
});
grid.render('grid');
ds.load(data);
});
还是有个缺点。 刚选中就被反选了,应该是数据刷新问题,记得grid可是设置的
似乎想起来了,以前做项目 用的是jsonStore,如果查询出的数据时不含有外键关联的数据的可以默认选中,有的话就不可以,这里这个store显然也是
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不晓得你的grid是什么东东
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询