通过表格的rowClassName属性,给行添加类名
.selectHigh{
background-color: rgb(234, 248, 258)!important;
}
const handleRowClick = (e: any, record: any) => {
let param = { type: record.type, key: record.key };
switch (title) {
case '省份':
setProvinceInfo(param);
break;
case '城市':
setCityInfo(param);
break;
case '区域':
setCountyInfo(param);
break;
default:
break;
}
};
return (<AdvancedTable
columns={column}
dataSource={data}
tableClassName={'table' + tableName}
bordered={false}
rowKey="key"
toolBarRender={false}
search={false}
loading={false}
scroll={{ x: 'max-content' }}
rowClassName={(record: any) => {
if (
(record.key == provinceInfo.key && title == '省份') ||
(record.key == cityInfo.key && title == '城市') ||
(record.key == countyInfo.key && title == '区域')
) {
// 选中行高亮
return `selectHigh`;
}
return '';
}}
onRow={(record) => {
return {
onClick: (e: any) => {
handleRowClick(e, record);
}, // 点击行
};
}}
tableAlertRender={false}
pagination={{
current: pageNum,
onChange: (page) => handlePageChange(page),
total: data?.length,
pageSize: 5,
size: 'small',
showSizeChanger: false,
hideOnSinglePage: true,
}}
/>)