# table单元格背景颜色

An image

onInit() {
    //设置背景颜色
    this.columns.forEach((x) => {
    if (x.field == 'ProductCode') {
        x.cellStyle = (row, rowIndex, columnIndex) => {
        if (row.ProductCode == '10044464880643') {
            return { background: '#ddecfd' };
        } else {
            return { background: '#eee' };
        }
        };
    }

    //如果根据行的某个值设置整行颜色
    //设置整行背景颜色
    // x.cellStyle = (row, rowIndex, columnIndex) => {
    //   if (row.ProductCode == '10044464880643') {
    //     return { background: '#ddecfd' };
    //   } 
    // };
    });

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23