admin管理员组文章数量:1416631
I have this sample code /
Ext.require([
'Ext.data.*',
'Ext.grid.*'
]);
function getRandomDate() {
var from = new Date(1900, 0, 1).getTime();
var to = new Date().getTime();
return new Date(from + Math.random() * (to - from));
}
function createFakeData(count) {
var firstNames = ['Ed', 'Tommy', 'Aaron', 'Abe'];
var lastNames = ['Spencer', 'Maintz', 'Conran', 'Elias'];
var data = [];
for (var i = 0; i < count ; i++) {
var dob = getRandomDate();
var firstNameId = Math.floor(Math.random() * firstNames.length);
var lastNameId = Math.floor(Math.random() * lastNames.length);
var name = Ext.String.format("{0} {1}", firstNames[firstNameId], lastNames[lastNameId]);
data.push([name, dob]);
}
return data;
}
Ext.onReady(function(){
Ext.define('Person',{
extend: 'Ext.data.Model',
fields: [
'Name', 'dob'
]
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
model: 'Person',
autoLoad: true,
proxy: {
type: 'memory',
data: createFakeData(10),
reader: {
type: 'array'
}
}
});
// create the grid
var x = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{text: "Name", width:120, dataIndex: 'Name'},
{text: "dob", width: 380, dataIndex: 'dob'}
],
renderTo:'example-grid',
width: 500,
height: 280
});
x.getSelectionModel().select(4);
});
On line 61 I want to make a selection in my grid, but it does not seems to have any effect. Can anyone tell me why?
I have this sample code http://jsfiddle/Xpe9V/414/
Ext.require([
'Ext.data.*',
'Ext.grid.*'
]);
function getRandomDate() {
var from = new Date(1900, 0, 1).getTime();
var to = new Date().getTime();
return new Date(from + Math.random() * (to - from));
}
function createFakeData(count) {
var firstNames = ['Ed', 'Tommy', 'Aaron', 'Abe'];
var lastNames = ['Spencer', 'Maintz', 'Conran', 'Elias'];
var data = [];
for (var i = 0; i < count ; i++) {
var dob = getRandomDate();
var firstNameId = Math.floor(Math.random() * firstNames.length);
var lastNameId = Math.floor(Math.random() * lastNames.length);
var name = Ext.String.format("{0} {1}", firstNames[firstNameId], lastNames[lastNameId]);
data.push([name, dob]);
}
return data;
}
Ext.onReady(function(){
Ext.define('Person',{
extend: 'Ext.data.Model',
fields: [
'Name', 'dob'
]
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
model: 'Person',
autoLoad: true,
proxy: {
type: 'memory',
data: createFakeData(10),
reader: {
type: 'array'
}
}
});
// create the grid
var x = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{text: "Name", width:120, dataIndex: 'Name'},
{text: "dob", width: 380, dataIndex: 'dob'}
],
renderTo:'example-grid',
width: 500,
height: 280
});
x.getSelectionModel().select(4);
});
On line 61 I want to make a selection in my grid, but it does not seems to have any effect. Can anyone tell me why?
Share Improve this question asked Jul 24, 2014 at 8:09 gefeigefei 19.9k9 gold badges54 silver badges70 bronze badges1 Answer
Reset to default 3The grid is still loading. You have to add a listener for the render event, then you can drop line 61. I updated your jsfiddle, see here: http://jsfiddle/Xpe9V/417/
var x = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{text: "Name", width:120, dataIndex: 'Name'},
{text: "dob", width: 380, dataIndex: 'dob'}
],
renderTo:'example-grid',
width: 500,
height: 280,
listeners: {
'render': function(ponent) {
if (this.store.isLoading() || this.store.getCount() == 0) {
this.store.on('load', function() {
this.getSelectionModel().select(4);
}, this, {single: true});
} else {
this.getSelectionModel().select(4);
}
}
}
});
本文标签: javascriptExtJs Grid How to set selectionStack Overflow
版权声明:本文标题:javascript - ExtJs Grid How to set selection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745256901a2650157.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论