Ext4 viewConfig getRowClass 背景颜色修改

本文探讨了如何利用CSS的.my_row_red.x-grid-cell类样式和JavaScript的getRowClass方法来实现网格面板中行背景颜色的动态变化,具体展示了在不同状态下的样式应用。

css

 .my_row_red .x-grid-cell {    //一定要加后面-cell class名称,否则无效

background-color: red;

}

 

js

new Ext.grid.panel({

     ...

     viewConfig : {

forceFit : true,

getRowClass : function(record, rowIndex, rowParams, store) {

if (record.data.status> 0) {

return 'my_row_red';   //返回的class name

}

}

}

})

修改表格或列表中选中行的默认背景色,可以通过多种方式实现,具体取决于使用的前端框架(如 ExtJS、Element UI、Ant Design 等)。以下是一些常见框架的具体方法和 CSS 样式调整示例。 ### ExtJS 6 中修改表格选中行的背景色 在 ExtJS 6 中,如果希望针对某个特定表格修改选中行的背景色,而是全局更改所有表格的样式,可以通过自定义 `rowStyle` 和鼠标事件来实现。例如: ```javascript Ext.create('Ext.grid.Panel', { // ...其他配置 selModel: { selType: 'checkboxmodel', mode: "MULTI", checkOnly: true }, viewConfig: { getRowClass: function(record, rowIndex, rowParams, store) { return 'custom-row-style'; // 自定义 CSS 类名 } } }); ``` 然后,在 CSS 文件中定义 `.custom-row-style` 类以覆盖默认的选中样式: ```css .custom-row-style .x-grid-row-selected { background-color: #fff !important; /* 设置为白色或其他颜色 */ } ``` 此外,为了处理鼠标悬停时的颜色变化,可以添加如下 CSS: ```css .x-grid-row-over .x-grid-cell { background-color: #f0f0f0 !important; } ``` ### Element UI 中修改表格选中行的背景色 在 Element UI 中,可以通过 CSS 覆盖 `.el-table__row.current-row` 的样式来修改选中行的背景色。例如: ```css .el-table__row.current-row > td { background-color: #ffffff !important; /* 设置为白色或其他颜色 */ } ``` 同时,如果你希望取消鼠标悬停时的高亮效果,可以添加以下 CSS: ```css .el-table__row:hover > td { background-color: transparent !important; } ``` ### Ant Design 中修改表格选中行的背景色 对于 Ant Design 的 `Table` 组件,可以通过设置 `rowClassName` 属性来自定义选中行的类名,并通过 CSS 修改背景色。例如: ```jsx <Table rowClassName={() => 'custom-ant-table-row'} /> ``` 然后在 CSS 文件中定义该类: ```css .custom-ant-table-row.ant-table-row-selected > td { background-color: #ffffff !important; /* 设置为白色或其他颜色 */ } ``` 同样地,如果需要去除鼠标悬停时的背景色,可以使用以下 CSS: ```css .ant-table-tbody > tr:hover > td { background-color: transparent !important; } ``` ### 使用 JavaScript 动态清除选中行的背景色 如果你希望在点击表格外部区域时清除选中行的背景色,可以通过监听点击事件并操作 DOM 来实现。例如: ```javascript document.addEventListener('click', function(event) { if (!event.target.closest('#myTable')) { var selectedRows = document.querySelectorAll('#myTable .el-table-tr.current-row'); selectedRows.forEach(function(row) { row.className = 'normal hy-table-tr'; // 恢复默认类名 }); } }); ``` 以上方法可以帮助你在同框架中灵活地修改表格选中行的默认背景色[^1]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值