简体   繁体   English

为什么不使用 vuejs 将新行添加到 ag-grid?

[英]Why are new rows not being added to ag-grid using vuejs?

I've got an ag-grid component in a vue.js application declared like this:我在 vue.js 应用程序中有一个 ag-grid 组件,声明如下:

<ag-grid-vue :enable-sorting="false"
                                 :enable-filtering="false"
                                 :suppressDragLeaveHidesColumns="true"
                                 :rowData="category.policyDocuments"
                                 :gridOptions="policyGridOptions"
                                 @cellValueChanged="savePolicyRow"
                                 @grid-ready="onPolicyGridReady($event, category)"
                                 class="w-100"
                                 style="height: 200px">
</ag-grid-vue>

Bound to this typescript view model:绑定到这个 typescript 查看 model:

export class PolicyListViewModel {
    status: PolicyDashboardStatus;

    policyLists: DocumentWalletPolicyDocumentList[] = [];

    gridApi: GridApi | null = null;

    policyDocuments: DocumentWalletDocumentViewModel[] = [];

    constructor(status: PolicyDashboardStatus) {
        this.status = status;
    }

    get shouldShow(): boolean {
        return this.policyDocuments.length > 0;
    }

    updateDocuments(): void {
        this.policyDocuments = this.policyLists
            .map(list => list.policyDocuments)
            .reduce((a, b) => a.concat(b), []);
    }
}

When my page first displays I get the right data.当我的页面第一次显示时,我得到了正确的数据。 When I call updateDocuments with new data the grid does not update.当我用新数据调用updateDocuments时,网格不会更新。 I have verified in vue devtools that the rowData prop is being updated.我已经在 vue devtools 中验证了rowData道具正在更新。 ag-grid documentation would suggest that the component should react to the change. ag-grid 文档建议组件应对更改做出反应。 Any ideas what I am doing wrong?知道我做错了什么吗?

Ah-ha.啊哈。 Finally figured it out, posting here in case it helps anyone else.终于弄明白了,张贴在这里以防它帮助其他人。

It looks like my problem was binding both gridOptions and rowData at the same time.看起来我的问题是同时绑定gridOptionsrowData Everything was working fine except for the the refresh when rowData was changed.除了更改rowData时的刷新外,一切都工作正常。 I'm assuming this is because the grid options had its own rowData property and the ag-grid wrapper was using the data from one copy and detecting changes on the other (or something like that).我假设这是因为网格选项有自己的rowData属性,而 ag-grid 包装器正在使用一个副本中的数据并检测另一个副本的变化(或类似的东西)。

I replaced the gridOptions binding with a columnDefs binding (in this case the only options I needed to set) and everything started working exactly as it should.我用columnDefs绑定替换了gridOptions绑定(在这种情况下,我需要设置的唯一选项),一切都开始正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM