Having trouble getting help?
Contact Support
Contact Support
Get row cell index in Vue Treegrid component
11 Jun 20245 minutes to read
You can get the specific row and cell index of the Tree Grid by using rowSelected
event of the treegrid. Here, we can get the row and cell index by using aria-rowindex (get row Index from tr element) and aria-colindex (column index from td element) attribute.
<template>
<div id="app">
<ejs-treegrid :dataSource="data" :treeColumnIndex="1" height='300px' idMapping='TaskID' parentIdMapping='parentID' :rowSelected='rowSelected' ref="treegrid">
<e-columns>
<e-column field="TaskID" headerText="Task ID" :isPrimaryKey='true' width="70" textAlign="Right"></e-column>
<e-column field="TaskName" headerText="Task Name" width="100" ></e-column>
<e-column field="StartDate" headerText="Start Date" format="yMd" width="100" textAlign="Right"></e-column>
<e-column field="EndDate" headerText="End Date" width="100" format="yMd" textAlign="Right"></e-column>
<e-column field="Duration" headerText="Duration" width="90" textAlign="Right"></e-column>
<e-column field="Priority" headerText="Priority" width="90" textAlign="Left"></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script setup>
import { provide } from "vue";
import { TreeGridComponent as EjsTreegrid, Page, ColumnDirective as EColumn, ColumnsDirective as EColumns } from "@syncfusion/ej2-vue-treegrid";
import { projectData } from "./datasource.js";
const data = projectData;
const rowSelected = function(args) {
alert("row index: "+args.row.getAttribute('aria-rowindex'));
alert("column index: "+args.target.closest('td').getAttribute('aria-colindex'));
};
provide('treegrid', [Page]);
</script>
<template>
<div id="app">
<ejs-treegrid :dataSource="data" :treeColumnIndex="1" height='300px' idMapping='TaskID' parentIdMapping='parentID' :rowSelected='rowSelected' ref="treegrid">
<e-columns>
<e-column field="TaskID" headerText="Task ID" :isPrimaryKey='true' width="70" textAlign="Right"></e-column>
<e-column field="TaskName" headerText="Task Name" width="100" ></e-column>
<e-column field="StartDate" headerText="Start Date" format="yMd" width="100" textAlign="Right"></e-column>
<e-column field="EndDate" headerText="End Date" width="100" format="yMd" textAlign="Right"></e-column>
<e-column field="Duration" headerText="Duration" width="90" textAlign="Right"></e-column>
<e-column field="Priority" headerText="Priority" width="90" textAlign="Left"></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import { TreeGridComponent, Page, ColumnDirective, ColumnsDirective } from "@syncfusion/ej2-vue-treegrid";
import { projectData } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-treegrid":TreeGridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
},
data() {
return {
data: projectData,
};
},
methods: {
rowSelected(args) {
alert("row index: "+args.row.getAttribute('aria-rowindex'));
alert("column index: "+args.target.closest('td').getAttribute('aria-colindex'));
}
},
provide: {
treegrid: [Page]
}
}
</script>