Angular AG-Grid - 比较行与格式

问题描述 投票:0回答:0

我是 Angular 的新手,正在玩 AG Grid。寻求帮助:

我有一个 4 列的 ag-grid:

  public columnDefs: ColDef[] = [
    { field: 'no' },
    { field: 'dateRange', cellRenderer: DateRangePickerComponent },
    { field: 'startDate', editable: true, sortable:true},
    { field: 'endDate', editable: true, sortable: true}
  ];

添加新的开始日期或结束日期后,我想继续进行以下检查:

  1. 如果 currentIndex value at startDate > previousIndex value at endDate 两个单元格都应该以红色突出显示。
  2. 如果 currentIndex value at endDate > nextIndex value at startDate 两个单元格都应该以红色突出显示
  3. 如果 1 和 2 不适用,则不是 highlithing

选项 1:通过 onCellValueChanged 事件实现它是否有意义? onCellValueChanged(事件:任何){ console.log('TestStart: ', this.gridApi.getValue('startDate', this.gridApi.getRowNode('2'))); 我怎样才能在这里访问某个单元格的值?它在这里只返回 null。 }

选项 2:是否可以在 defaultColDef 中定义该规则? 类似于以下? (不起作用)

defaultColDef = {
    cellStyle: function(params) {
        const rowIndex = params.node.rowIndex;
        const columnId = params.colDef.field;
        const previousRowIndex = rowIndex - 1;
        const nextRowIndex = rowIndex + 1;
        const currentValueStart = params.value;
        const currentValueEnd = params.value;
        const previousValueEnd = params.api.getDisplayedRowAtIndex(previousRowIndex).data[columnId];;
        const nextValueStart = params.api.getDisplayedRowAtIndex(nextRowIndex).data[columnId];

        if (currentValueStart < previousValueEnd) || (currentValueEnd > nextValueStart {
          return { 'background-color': 'red' };
        }
  
        return { 'background-color': null};
      }
}

谢谢和亲切的问候

angular ag-grid
© www.soinside.com 2019 - 2024. All rights reserved.