我是 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:通过 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};
}
}
谢谢和亲切的问候