在ExtJs 3.3.1中,如何在不单击EditorGrid的情况下显示组合框下拉列表?
我正在使用extjs3.3.1 在EditorGrid中,我的“可编辑”列有一个组合框作为其编辑器。如何使组合框始终显示在每行中?这意味着,用户不必单击单元格就知道那里有一个组合框。目前,我已将clicksToEdit设置为1,但我希望可以将其设置为0(我尝试了) 请参阅下面的一些代码以查看我的当前配置在ExtJs 3.3.1中,如何在不单击EditorGrid的情况下显示组合框下拉列表?,extjs,combobox,grid,extjs3,Extjs,Combobox,Grid,Extjs3,我正在使用extjs3.3.1 在EditorGrid中,我的“可编辑”列有一个组合框作为其编辑器。如何使组合框始终显示在每行中?这意味着,用户不必单击单元格就知道那里有一个组合框。目前,我已将clicksToEdit设置为1,但我希望可以将其设置为0(我尝试了) 请参阅下面的一些代码以查看我的当前配置 var combo = new Ext.form.ComboBox({ typeAhead: true, triggerAction: 'all', lazyRender
var combo = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
lazyRender: true,
mode: 'local',
store: new Ext.data.ArrayStore({
id: 0,
fields: [
'statusId',
'displayText'],
data: data
}),
valueField: 'statusId',
displayField: 'displayText'
});
var cm = new Ext.grid.ColumnModel({
columns: [{
id: 'orderId',
header: 'ID',
dataIndex: 'id',
width: 50
}, {
header: 'Status',
dataIndex: 'status',
width: 130,
editor: (data.length == 1) ? null : combo,
renderer: Ext.util.Format.comboRenderer(combo)
}, {
id: 'orderSummary',
header: 'Summary',
dataIndex: 'summary',
renderer: this.renderSummary
}]
});
var orderGrid = new Ext.grid.EditorGridPanel({
store: this.getOrderStore(),
cm: cm,
autoExpandColumn: 'orderSummary',
clicksToEdit: 1
});
我认为您需要在显示下拉图标的组合框中添加一个特殊的css。Ext JS本机不支持这一点。下面是一个如何实现的示例:
var companyColumn = {
header: 'Company Name',
dataIndex: 'company',
renderer: function(value, metaData, record, rowIndex, colIndex, store) {
// provide the logic depending on business rules
// name of your own choosing to manipulate the cell depending upon
// the data in the underlying Record object.
if (value == 'whatever') {
//metaData.css : String : A CSS class name to add to the TD element of the cell.
//metaData.attr : String : An html attribute definition string to apply to
// the data container element within the table
// cell (e.g. 'style="color:red;"').
metaData.css = 'name-of-css-class-you-will-define';
}
return value;
}
}
或者您可以使用
Ext.grid.TemplateColumn
并指定tpl
配置。这将自动为列中的单元格生成渲染器,并应用tpl
这是我想出的解决办法
.x-grid3-col-status
{
background-image: url(Image/trigger-single.gif);
background-position: right;
background-repeat: no-repeat;
cursor: pointer;
}
Ext.util.Format.comboRenderer = function (combo) {
return function (value, metaData, record, rowIndex, colIndex, store) {
var record = combo.findRecord(combo.valueField, value);
return record ? record.get(combo.displayField) : combo.valueNotFoundText;
}
}
var combo = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
lazyInit: false,
lazyRender: true,
mode: 'local',
editable: false,
store: new Ext.data.ArrayStore({
id: 0,
fields: [
'statusId',
'displayText'
],
data: data
}),
valueField: 'statusId',
displayField: 'displayText',
listeners: {
'focus': {
fn: function (comboField) {
comboField.doQuery(comboField.allQuery, true);
comboField.expand();
}
, scope: this
}
, 'select': {
fn: function (comboField, record, index) {
comboField.fireEvent('blur');
}
, scope: this
}
}
});
var cm = new Ext.grid.ColumnModel({
defaults: {
sortable: true
},
columns: [
{
id: 'orderId',
header: 'ID',
dataIndex: 'id',
width: 50
}, {
header: 'Status',
id: 'status',
dataIndex: 'status',
width: comboColumnWidth,
editor: combo,
renderer: Ext.util.Format.comboRenderer(combo)
}, {
id: 'orderSummary',
header: 'Summary',
dataIndex: 'summary',
renderer: this.renderSummary
}
]
});
var orderGrid = new Ext.grid.EditorGridPanel({
store: this.getOrderStore(),
cm: cm,
autoExpandColumn: 'orderSummary',
title: title,
clicksToEdit: 1
});