0

So I have this itemlist.vue file

  <div>
    <div>
      <ag-table
        style=" height: 650px;"
        class="ag-theme-balham"
        :column-defs="columnDefs"
        :row-data="rowData"
      />
    </div>
  </div>
</template>

<script>
import AgTable from "../components/AgTable";
import editRenderer from "../components/AgGridRenderers/editDeleteRenderer.vue";

export default {
    components: {
        AgTable
    },
    data: () => ({
        users: [],
        columnDefs: null,
        rowData: null,
        editR: editRenderer
    }),
    mounted () {
        this.columnDefs = [
            { headerName: "Name", field: "name", sortable: true, filter: true },
            { headerName: "e-Mail", field: "email", sortable: true, filter: true },
            { headerName: "Contact", field: "contact", sortable: true, filter: true },
            { headerName: "Contact", field: "contact", sortable: true, filter: true, cellRenderer: editRenderer }
        ];
        this.rowData = [
            { name: "Robin Sharma", email: "robin@sharma.com", contact: 8508035076 },
            { name: "Amish Tripathi", email: "amish@tripathi.com", contact: 9250035054 },
            { name: "Zig Ziglar", email: "zig@ziglar.com", contact: 9206635030 },
            { name: "Paulo Coelho", email: "paolo@coelho.com", contact: 7288012335 }
        ];
    },
    methods: {
        loadUsers () {
            // console.log("Loading Users from api.");
        }
    }
};
</script>

And index.vue file for Ag grid table as

<template>
  <div>
    <ag-grid-vue
      style=" height: 650px;"
      class="ag-theme-balham"
      :column-defs="_props.columnDefs"
      :row-data="_props.rowData"
      :framework-components="frameworkComponents"
    />
  </div>
</template>
<script>
import "ag-grid-community/dist/styles/ag-grid.css";
import "ag-grid-community/dist/styles/ag-theme-balham.css";

import { AgGridVue } from "ag-grid-vue";
import editRenderer from "../AgGridRenderers/editDeleteRenderer.vue";

export default {
    components: {
        AgGridVue
    },
    props: [
        "column-defs", "row-data"
    ],
    data: () => ({
        frameworkComponents: {
            editRenderer
        }
    }),
    mounted () {
        console.log(this._props.columnDefs, this._props.rowData);
    }
};
</script>

And editrenderer.vue file as:

<template>
  <div>
    <span>
      <button @click="sayHi"> Edit Item </button>
    </span>
  </div>
</template>

<script>
export default {
    created () {
        console.log("Hello from Edit");
    },
    methods: {
        sayHi () {
            alert("Hi");
        }
    }
};
</script>

And all I am getting in the DOM is empty edit-renderer tags

Doesn't AgGrid support cellRenderers in Vue Js? In the end the imported component appears as a vue component in the Dom if used separately as a common Dom element. Does that mean we explicitly have to compile it somehow? I also tried using setTimeOut before initializing columnDefs and rowData where AgTable is used. but still it doesn't show anything in the table.

Yogesh Vadekar
  • 119
  • 2
  • 9
  • 1
    you should initialize your nested data in `data`. Vue can't watch nested data if it is added on the fly. Check this https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats So `this.columnDefs` and `this.rowData` should be initialized in `data` or move this to computed. – Tomasz Kostuch Mar 09 '20 at 07:34
  • No. Unfortunately this solution is not giving any different output. – Yogesh Vadekar Mar 09 '20 at 08:21
  • while setting rowData, it gives error which says callback is not a function and when clicked on it, it takes me to following part of the code: ```Adapter.prototype.getGui = function () { var callbackResult = callback(this.params); var type = typeof callbackResult; if (type === 'string' || type === 'number' || type === 'boolean') { return _.loadTemplate('' + callbackResult + ''); } else { return callbackResult; } };``` – Yogesh Vadekar Mar 09 '20 at 10:50
  • ```AgComponentUtils.prototype.adaptCellRendererFunction = function (callback) { ``` //This line expects a paramater 'callback' which I don't understand comes from which part of the code!! – Yogesh Vadekar Mar 09 '20 at 10:59
  • Well I tried converting that .vue file of renderer to .js and the problem still persists. Can anyone detect the bug please?? – Yogesh Vadekar Mar 09 '20 at 12:54

1 Answers1

0

Ok, so what I did was add some missing properties to ag-grid-vue element such as grid-options, context and grid-ready, and add refresh function to the renderer component, and convert all related components from simple "export default{" to "export default Vue.extends({". I think this problem was resolved. Though, I am getting 'this is undefined' error now. Ag-grid should clarify which parameters are compulsory other than rowData and colDefs with their purpose.

Yogesh Vadekar
  • 119
  • 2
  • 9