问题
I have an Extjs Editor Grid panel in which i have to change the css of one column depending upon the value of another column value then how to do it i cannot use renderer function because it works on onload is there any other way i am attaching code in which i have gender column and id column so when gender column select male then background colour of ID should change to Pink colour else not so how to do it.
{
id: 'value',
name: 'value',
header: 'Gender',
dataIndex: 'insured',
width: 100,
editor: new fm.ComboBox({
typeAhead: true,
displayField: 'gender',
mode: 'local',
transform: 'gender',
triggerAction: 'all',
selectOnFocus: true,
forceSelection: true,
stripeRows: true,
lazyRender: true,
listeners: {
}
}
})
},
{
id: 'ID',
name: 'ID',
header: 'ID',
dataIndex: 'ID',
width: 100,
hidden: true,
editor: new fm.TextField({
allowBlank: true,
maxLength: 500
})
}
回答1:
This will work for simple rendering
CSS:
.custom-column
{
background-color: #ccc;
}
JavaScript:
columns: [{
dataIndex: 'name',
renderer: function (value, meta) {
meta.css = 'custom-column';
return value;
}
}]
Edit:
You can use getRowClass to apply custom CSS classes to rows during rendering.
Override this function to apply custom CSS classes to rows during rendering. This function should return the CSS class name (or empty string '' for none) that will be added to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string (e.g. 'my-class another-class').
Javascript:
columns: [{
dataIndex: 'ID',
...
tdCls: 'ID' //add table css class
}],
viewConfig: {
getRowClass: function(record, index) {
var gender = record.get('insured');
if (gender === 0) {
//male
return 'gender-male';
} else if (gender === 1) {
//female
return 'gender-female';
} else {
//unknown
return 'gender-unknown';
}
}
}
Additional CSS:
.gender-male .ID {
background-color: #088da5;
}
.gender-female .ID {
background-color: #f799af;
}
.gender-unknown .ID {
background-color: #BADA55;
}
来源:https://stackoverflow.com/questions/15110710/extjs-grid-panel-one-column-background-color-change-on-another-column-value