Extjs 访问Ext.grid.Panel';s列组合框选择
我有一个Ext.grid.Panel,其中显示了几个列。一个是带有一组静态预定义可选值的组合框 在某些数据项(列)上,我想禁用组合框。禁用取决于另一列值 我该怎么做 更多背景: 在组合框中呈现列的单元格数据后,我无法在afterrender-侦听器中反向引用列的数据模型 如果我能够重新引用数据对象,那么我可以决定是否允许从组合框中进行选择。某些列(数据元组)允许从组合框中选择不同的值,其他列则不允许 背景: 面板的单元格编辑已打开。我有一列,它是一个下拉列表,其中包含从接收到的数据中获取的确定值 使用afterrender方法可以引用的存储不是保存所有表数据的存储。它只保存列的静态大中低数据。但我需要这一排的储备;或者最好是存储在更全局的存储中的正确数据行Extjs 访问Ext.grid.Panel';s列组合框选择,extjs,combobox,extjs6-classic,Extjs,Combobox,Extjs6 Classic,我有一个Ext.grid.Panel,其中显示了几个列。一个是带有一组静态预定义可选值的组合框 在某些数据项(列)上,我想禁用组合框。禁用取决于另一列值 我该怎么做 更多背景: 在组合框中呈现列的单元格数据后,我无法在afterrender-侦听器中反向引用列的数据模型 如果我能够重新引用数据对象,那么我可以决定是否允许从组合框中进行选择。某些列(数据元组)允许从组合框中选择不同的值,其他列则不允许 背景: 面板的单元格编辑已打开。我有一列,它是一个下拉列表,其中包含从接收到的数据中获取的确定值
Ext.define( 'MyTable',{
extend: 'Ext.grid.Panel',
xtype:'myXtypeName',
mixins: {
field: 'Ext.form.field.Field'
},
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1} )
],
store: Ext.create( 'Ext.data.Store', {
data: [],
autoLoad: false,
} ),
columns: [
{
header: '#',
dataIndex: 'id',
},
{
header: 'Severity',
dataIndex:'correctionSeverity',
sortable: false,
renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
var myTable = Ext.ComponentQuery.query('myXtypeName');
myTable[0].severityChangeable[ record.id ] = record.data.correctionType == 'Changed';
return value;
},
editor: Ext.create( 'Ext.form.field.ComboBox', {
queryMode: 'remote',
store: Ext.create( 'Ext.data.Store', {
fields: ['id', 'text'],
data: [ { id:'entry0', text:'Big' },
{ id:'entry1', text:'Medium' },
{ id:'entry2', text:'Low' } ],
} ),
valueField: 'id',
displayField: 'text',
editable: false,
forceSelection: true,
listeners: {
afterrender: function(combo, eOpts) {
// how to access the underlaying entry (row data) instead of just the column?
// by another value of the
var rowData = ???;
if ( rowData['preventColumnDropdown'] == true ) {
combo.disable();
}
},
change: function(combo, newValue, oldValue, eOpts) {
// do something
},
}
}),
}
],
initComponent: function() {
this.callParent(arguments);
this.initField();
},
setValue: function(value) {
this.store.loadData( value );
},
});
我希望我的观点和问题是可以理解的。请让我知道如果不是这样
我正在运行ExtJS 6.0.0 classic。afterrender事件是错误的事件,因为相同的combobox实例被所有行重用。因此,在组合框实例化时,行数据不可用 在开始单元格编辑之前,您可能希望使用
单元格编辑插件上的事件来修改编辑器:
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners: {
beforeedit: function(editor, context, eOpts) {
// Only if the combo column is being edited:
if(context.column.dataIndex == "myComboDataIndex") {
// Disable combobox depending on:
editor.setDisabled(!context.record.get("AllowComboDataEdit"));
// or just return false to stop edit altogether:
// return context.record.get("AllowComboDataEdit");
}
}
}
});
谢谢你的提示。它确实有效(几乎)!beforeedit必须嵌套一个侦听器:{beforeedit:function(…}),然后它对我来说非常适合。@DirkSchumacher谢谢你,我更新了我的答案以反映你的评论。