【问题标题】:ag-grid-vue: how to detect row click?ag-grid-vue:如何检测行点击?
【发布时间】:2021-01-30 20:39:03
【问题描述】:

我正在关注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', sortable: true, filter: true },
      {headerName: 'Price', field: 'price', sortable: true, 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

我在这里缺少什么?

【问题讨论】:

    标签: javascript vue.js ag-grid ag-grid-vue onrowclick


    【解决方案1】:

    替换此行

    :rowClicked="onRowClicked"
    

    @rowClicked="onRowClicked"
    

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

    现场演示

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-14
      • 2019-10-26
      • 1970-01-01
      • 2020-01-08
      • 2017-09-16
      • 2019-07-28
      • 2018-10-13
      • 1970-01-01
      相关资源
      最近更新 更多