当我选择另一个单元格中的值时如何更改单元格的值

时间:2019-10-21 15:47:34

标签: angular6 ag-grid-angular

我目前在角6下的应用中使用ag-grid,我的问题是: 我有一排3列,| A | B | C |

A是带有某些名称的选择 当我在行A中选择一个值时,我希望BC(同一行)根据A中的日期更改其值。

A = { id:number , aStart:Date, aEnd:Date }

我尝试使用startEditingCell和其他方式,但没有一个起作用。

哪种方法是正确的?

export interface Delivery {
    id: number;
    deliveryCode: string;
    startPeriodDate: Date;
    endPeriodDate: Date;
    description: string;
    inactive: boolean;
}

export class lineColumn {
    deliveryid: number
    startDate: Date
    endDate: Date
}
const columns = {
                headerName: 'Delivery',
                colId: 'delivery',
                field: 'id',
                editable: this.isGridEditableOnCondition,
                cellEditor: 'agRichSelectCellEditor',
                cellRenderer: this.deliveryFormatter.bind(this),
                cellEditorParams: (params) => {
                    return {
                        values: this.deliveries.map((delivery) => delivery.id),
                        formatValue: this.deliveryFormatter.bind(this),
                        displayPropertyName: 'deliveryCode',
                        valuePropertyName: 'deliveryCode',
                        displayFormat: 'deliveryCode',
                    };
                },
                onCellValueChanged: (params) => {
                    // when this value changes, the other 2 columns must change with the values of dates that delivery has (but can be still editables)
                    params.api.refreshCells();
                },
            },
            {
                headerName: 'Shipping Start Date',
                colId: 'shippingStartDate',
                field: startDate,
                editable: this.isGridEditable,
                valueFormatter: this.uiService.dateFormatter,
                cellEditor: 'atrDate',
            },
            {
                headerName: 'Shipping End Date',
                colId: 'shippingEndDate',
                field: endDate,
                editable: this.isGridEditable,
                valueFormatter: this.uiService.dateFormatter,
                cellEditor: 'atrDate',
            },

1 个答案:

答案 0 :(得分:0)

最后:

 onCellValueChanged: (params) => {

                        const api: agGrid.GridApi = params.api;
                        const delivery = this.masterdata.deliveries.find((d: Delivery) => d.deliveryId === params.newValue);
                        api.getRowNode(params.node.rowIndex).setDataValue('shippingStartDate', delivery.startPeriodDate);
                        api.getRowNode(params.node.rowIndex).setDataValue('shippingEndDate', delivery.endPeriodDate);

                        api.refreshCells();
                    }
                },