如何添加列:编辑,删除?

时间:2019-03-30 12:08:45

标签: vue.js ag-grid

我想使用vue ag-grid。所以我看过Get Started with ag-Grid in Your Vue Project 文章。

但是我找不到如何将delete列添加为链接按钮的任何示例吗?

<a :click="handleDelete">delete</a>

handleDelete(itemData) {
 // should open popup here base on itemData…
}

这是我正在使用的代码:

<template>
    <ag-grid-vue style="width: 500px; height: 500px;"
                 class="ag-theme-balham"
                 :columnDefs="columnDefs"
                 :rowData="rowData">
    </ag-grid-vue>
</template>

    this.columnDefs = [
                {headerName: 'Make', field: 'make'},
                {headerName: 'Model', field: 'model'},
                {headerName: 'Price', field: 'price'}
            ];

            this.rowData = [
                {make: 'Toyota', model: 'Celica', price: 35000},
                {make: 'Ford', model: 'Mondeo', price: 32000},
                {make: 'Porsche', model: 'Boxter', price: 72000}
            ];

1 个答案:

答案 0 :(得分:1)

您需要为自定义列定义cellRendererFramework,如下所示:

this.columnDefs = [
  { headerName: 'Make', field: 'make' },
  { headerName: 'Model', field: 'model' },
  { headerName: 'Price', field: 'price' },
  { headerName: 'Delete', cellRendererFramework: 'DeleteCell' }
];

还要确保您注册了DeleteCell组件:

components: {
  AgGridVue,
  DeleteCell,
},