我有一个名为“grid”的网格,onload 中有行被插入到网格中。 Some Rows 将是绿色的将成功输入行,而背景颜色为红色的行将有错误。我让它在某个时候工作,但错误行将被添加到背景颜色为红色的网格中。然后,当我尝试添加一个新行以向其中输入新数据时,所有行都变白了。然后就停止了一起工作。我试过了
store.insert(0, r).addClass('error-row');
和
Ext.fly(grid.getView().getRow(0)).addClass('error-row');
和
var cls ='error-row'
addRowClass : function(rowId, cls) {
var row = this.getRow(rowId);
if (row) {
this.fly(row).addClass(cls);
}
}
和
grid.getView().getRowClass = function(record, index, rp ,store) {
return 'error-row';
};
我不确定该怎么做。
CSS
<style>
.error-row .x-grid-cell {
background-color: #990000 !important;
}
.new-row .x-grid-cell {
background-color: #F5F2F3 !important;
}
</style>
最佳答案
viewConfig 属性应该为您指明正确的方向——使用来自 Ext 网格示例的代码,添加:
- cls 字段为记录定义类
- grid 配置的 viewConfig 属性
代码如下所示:
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone', 'cls'],
data:{'items':[
{ 'name': 'Lisa', "email":"lisa@simpsons.com", "phone":"555-111-1224", "cls":"new-row" },
{ 'name': 'Bart', "email":"bart@simpsons.com", "phone":"555-222-1234", "cls":"new-row" },
{ 'name': 'Homer', "email":"home@simpsons.com", "phone":"555-222-1244", "cls":"new-row" },
{ 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254", "cls": "error-row" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
id: 'MyGrid',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ header: 'Name', dataIndex: 'name'},
{ header: 'Email', dataIndex: 'email', flex: 1},
{ header: 'Phone', dataIndex: 'phone'}
],
viewConfig: {
getRowClass: function(record, rowIndex, rowParams, store){
return record.get('cls');
}
},
height: 200,
width: 400,
renderTo: Ext.getBody()
});
关于javascript - 更改行 extjs4 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9114496/