viewConfig 属性应该为您指明正确的方向 - 使用 Ext 网格示例中的代码,添加:
- cls 字段来定义记录的类
- viewConfig 属性到网格的配置
代码如下所示:
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone', 'cls'],
data:{'items':[
{ 'name': 'Lisa', "email":"[email protected] /cdn-cgi/l/email-protection", "phone":"555-111-1224", "cls":"new-row" },
{ 'name': 'Bart', "email":"[email protected] /cdn-cgi/l/email-protection", "phone":"555-222-1234", "cls":"new-row" },
{ 'name': 'Homer', "email":"[email protected] /cdn-cgi/l/email-protection", "phone":"555-222-1244", "cls":"new-row" },
{ 'name': 'Marge', "email":"[email protected] /cdn-cgi/l/email-protection", "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()
});