【问题标题】:how to change the value of a cell when I choose a value in another当我在另一个单元格中选择一个值时如何更改单元格的值
【发布时间】:2020-02-17 18:01:20
【问题描述】:

我目前在 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',
            },

【问题讨论】:

  • 请提供一些代码。我们需要了解这些值是如何选择的,哪些代码试图更改这些值,以及它在工作时会发生什么。给我们一些可以合作的东西,这样我们就可以帮助您调试/提出解决方案
  • 我已经完成了! :)

标签: angular6 ag-grid-angular


【解决方案1】:

最后:

 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();
                    }
                },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-28
    • 2012-05-15
    • 2020-12-14
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多