簡體   English   中英

ag-grid-vue:如何檢測行點擊?

[英]ag-grid-vue: how to detect row click?

我正在按照此處的示例進行操作。

一切正常,現在我想檢測行點擊並獲取事件的數據。

這是我的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方法。

我在這里缺少什么?

替換這一行

:rowClicked="onRowClicked"

@rowClicked="onRowClicked"

使ag-grid-vue組件在選擇一行時發出事件。

現場演示

編輯 64387203/ag-grid-vue-how-to-detect-row-click

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM