Bbb*_*Bbb 2 datagrid combobox extjs extjs4
我已经看到类似的问题在其他地方没有得到答案.我想在一个列中有一个组合框,里面有两个选项(ASC,DEC).我希望它显示在每一行中,或者至少在未选中时显示其值.
我知道在每一行中渲染一个组合框并不是一个"好主意",但在这种情况下,我知道我最多会有大约20行,所以它不应该是一个大问题.如果无法做到这一点,我想从组合框显示中选择一个值.目前我只是在点击一行时出现组合框,这没有多大意义,因为除非你正在制作它,否则你看不到你的选择.这是什么解决方案?
此外,我想摆脱更改并取消当我点击一行时弹出的按钮,我只是想能够使用组合框编辑单元格,并让它自动更改/保存.
您可以为combo
.设置默认值.
然后应该在启动时渲染.
使用电池renderer
来render
了displayField
的combo
到您的网格.下面是一个工作示例,可以在其中一个API代码框中显示海报.
工作JSFiddle
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone', 'id'],
data: {
'items': [{
"name": "Lisa",
"email": "lisa@simpsons.com",
"phone": "555-111-1224",
"id": 0
}, {
"name": "Bart",
"email": "bart@simpsons.com",
"phone": "555-222-1234",
"id": 1
}, {
"name": "Homer",
"email": "home@simpsons.com",
"phone": "555-222-1244",
"id": 2
}, {
"name": "Marge",
"email": "marge@simpsons.com",
"phone": "555-222-1254",
"id": 3
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
// the renderer. You should define it within a namespace
var comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField));
};
}
// the combo store
var store = new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
[1, "Option 1"],
[2, "Option 2"]
]
});
// the edit combo
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
// demogrid
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
header: 'Name',
dataIndex: 'name',
editor: 'textfield'
}, {
header: 'Email',
dataIndex: 'email',
flex: 1,
editor: {
xtype: 'textfield',
allowBlank: false
}
}, {
header: 'Phone',
dataIndex: 'phone'
}, {
header: 'id',
dataIndex: 'id',
editor: combo,
renderer: comboBoxRenderer(combo)
}],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10945 次 |
最近记录: |