更改行extjs4的背景颜色
Change background color of row extjs4
我有一个名为"grid"的网格,加载时有行插入到网格中。某些绿色行将成功输入行,而背景色为红色的行将出现错误。我在某个时候让它工作了,但错误行会被添加到背景色为红色的网格中。然后,当我试图添加新行以输入新数据时,所有的行都变成了白色。然后这一切都停止了。我试过
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字段,用于定义记录的类
- 网格配置的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()
});
相关文章:
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何使用jquery更改html中的背景颜色
- Javascript对象类在单击时打开窗口进行颜色选择,并在更改时替换对象背景颜色
- JS幻灯片与CSS背景颜色变化
- DT数据表背景颜色为黑色,但仍有悬停和选择颜色
- Javascript通过列表项的函数和css来更改背景颜色
- Javascript没有从数组中选择背景颜色
- 使用圆中的数组更改背景颜色项目
- 如何用jquery动画改变背景颜色,就像一个过渡
- 使用jquery交换并保存背景颜色
- j查询如何设置/取消设置下拉菜单的背景颜色
- 使用angularjs根据时间更改背景颜色
- 设置Dojo量表的背景颜色
- javascript样式的背景颜色在设置时闪烁.ASP.NET
- 使用javascript更改任意文本的背景颜色
- 在用Javascript更改背景颜色后:hover don'不要改变颜色
- 图像内部的透明背景颜色不受影响
- jQuery mobile-动态更改ui页面背景颜色
- 切换按钮的背景颜色
- JavaScript更改类的背景颜色