使用 selectionModel 获取网格内的复选框值
Get checkbox value inside grid with selectionModel
如何从 Ext.grid.Panel 中的 selectionModel 中获取复选框的值?
我在 grid.getView().getRow(0).cells[0] 中找不到属性
您可以使用 selModel 获取选定的记录,如下所示
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['name', 'email', 'phone']
});
var userStore = Ext.create('Ext.data.Store', {
model: 'User',
data: [{
name: 'Lisa',
email: 'lisa@simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart@simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer@simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge@simpsons.com',
phone: '555-222-1254'
}, {
name: 'Shreya',
email: 'marge@simpsons.com',
phone: '555-222-1254'
}
]
});
Ext.create({
xtype: 'panel',
title: 'Grid Panel',
renderTo: Ext.getBody(),
items: [{
xtype: 'grid',
id: 'mygrid',
store: userStore,
storeId: 'mystore',
width: 400,
height: 200,
selModel: {
selType: 'checkboxmodel',
checkOnly: true,
injectCheckbox: 0,
showHeaderCheckbox: false,
listeners: {
}
},
title: 'Application Users',
columns: [{
text: 'Name',
width: 100,
sortable: false,
hideable: false,
dataIndex: 'name'
}, {
text: 'Email Address',
width: 150,
dataIndex: 'email',
hidden: true
}, {
text: 'Phone Number',
flex: 1,
dataIndex: 'phone'
}]
},{
xtype: 'panel',
items: [{
xtype: 'button',
text: 'get selected record',
handler: function() {
var myGrid = Ext.getCmp('mygrid');
var selections = myGrid.getSelections();
console.log(selections);
}
}]
}]
})
//Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
}
});
Link 工作 Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/2l15
如何从 Ext.grid.Panel 中的 selectionModel 中获取复选框的值?
我在 grid.getView().getRow(0).cells[0] 中找不到属性
您可以使用 selModel 获取选定的记录,如下所示
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['name', 'email', 'phone']
});
var userStore = Ext.create('Ext.data.Store', {
model: 'User',
data: [{
name: 'Lisa',
email: 'lisa@simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart@simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer@simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge@simpsons.com',
phone: '555-222-1254'
}, {
name: 'Shreya',
email: 'marge@simpsons.com',
phone: '555-222-1254'
}
]
});
Ext.create({
xtype: 'panel',
title: 'Grid Panel',
renderTo: Ext.getBody(),
items: [{
xtype: 'grid',
id: 'mygrid',
store: userStore,
storeId: 'mystore',
width: 400,
height: 200,
selModel: {
selType: 'checkboxmodel',
checkOnly: true,
injectCheckbox: 0,
showHeaderCheckbox: false,
listeners: {
}
},
title: 'Application Users',
columns: [{
text: 'Name',
width: 100,
sortable: false,
hideable: false,
dataIndex: 'name'
}, {
text: 'Email Address',
width: 150,
dataIndex: 'email',
hidden: true
}, {
text: 'Phone Number',
flex: 1,
dataIndex: 'phone'
}]
},{
xtype: 'panel',
items: [{
xtype: 'button',
text: 'get selected record',
handler: function() {
var myGrid = Ext.getCmp('mygrid');
var selections = myGrid.getSelections();
console.log(selections);
}
}]
}]
})
//Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
}
});
Link 工作 Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/2l15