ag-grid-vue:如何检测行点击?

问题描述

我正在跟踪示例here

一切正常,现在我想检测一次单击并获取事件的数据。

这是我的App.vue

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

<script>
import {AgGridVue} from "ag-grid-vue";

export default {
  name: 'App',data() {
    return {
      columnDefs: null,rowData: null
    }
  },components: {
    AgGridVue
  },methods:{
    onRowClicked(params) {
      console.log(params);
      console.log(params.node.data);
    }
  },beforeMount() {
    this.columnDefs = [
      {headerName: 'Make',field: 'make',sortable: true,filter: true },{headerName: 'Model',field: 'model',{headerName: 'Price',field: 'price',filter: true }
    ];

    fetch('https://raw.githubusercontent.com/ag-grid/ag-grid/master/grid-packages/ag-grid-docs/src/sample-data/smallRowData.json')
        .then(result => result.json())
        .then(rowData => this.rowData = rowData);
  }
}
</script>

<style>
@import "../node_modules/ag-grid-community/dist/styles/ag-grid.css";
@import "../node_modules/ag-grid-community/dist/styles/ag-theme-alpine.css";
</style>

但是,当我单击一行时,不会调用方法onRowClicked

在这里缺少什么?

解决方法

替换此行

:rowClicked="onRowClicked"

使用

@rowClicked="onRowClicked"

要使ag-grid-vue组件在选定一行时发出事件。

实时演示

Edit 64387203/ag-grid-vue-how-to-detect-row-click