【问题标题】:Ag-grid:Duplicated cell values highlightAg-grid:重复的单元格值突出显示
【发布时间】:2022-12-15 13:19:19
【问题描述】:

如果特定列中的单元格值重复,则使用 ag-grid 突出显示该单元格

重复的单元格应使用红色边框突出显示

【问题讨论】:

    标签: ag-grid ag-grid-vue datagridviewcellstyle


    【解决方案1】:

    您可以通过遍历行数据来检测重复值,然后将检测到的重复值传递给自定义 cellStyle 函数,从而实现重复突出显示。

      defaultColDef = {
        cellStyle: function(params) {
            const columnId = params.colDef.field;
            const currentValue = params.value;
            const duplicates = params.context.duplicates;
    
            if (columnId in duplicates && duplicates[columnId] == currentValue){
              return { 'background-color': 'red' };
            }
      
            return { 'background-color': null};
          }
      }
    
      ngOnInit() {
        for (let key in this.rowData[0]) {
          let seenValues = new Set<string>()
          for (let i in this.rowData){
            const item = this.rowData[i]
            if (seenValues.has(item[key])){
              this.duplicates[key] = item[key];
            } else {
              seenValues.add(item[key]);
            }
          }
        }  
      }
    

    这是一个例子:

    这是代码: https://stackblitz.com/edit/ag-grid-duplicates-highlighting-6adsz6

    【讨论】:

      猜你喜欢
      • 2019-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 2020-08-20
      • 1970-01-01
      • 2019-08-19
      • 1970-01-01
      相关资源
      最近更新 更多