Having trouble getting help?
Contact Support
Contact Support
Enable disable grid and its actions in Vue Treegrid component
11 Jun 20249 minutes to read
You can enable/disable the Tree Grid and its actions by applying/removing corresponding CSS styles.
To enable/disable the Tree Grid and its actions, follow the given steps:
Step 1:
Create CSS class with custom style to override the default style of Tree Grid.
.disabletreegrid {
pointer-events: none;
opacity: 0.4;
}
.wrapper {
cursor: not-allowed;
}
Step 2:
Add/Remove the CSS class to the Tree Grid in the click event handler of Button.
btnClick(args) {
if (this.$refs.treegrid.$el.classList.contains('disablegrid')) {
this.$refs.treegrid.$el.classList.remove('disablegrid');
document.getElementById("TreeGridParent").classList.remove('wrapper');
}
else {
this.$refs.treegrid.$el.classList.add('disablegrid');
document.getElementById("TreeGridParent").classList.add('wrapper');
}
}
In the below demo, the button click will enable/disable the Tree Grid and its actions.
<template>
<div id="app">
<div>
<ejs-button iconCss="e-icons e-play-icon" cssClass="e-flat" :isPrimary="true" :isToggle="true" v-on:click="btnClick">Enable/Disable Grid</ejs-button>
<div id="TreeGridParent">
<ejs-treegrid :dataSource="data" :treeColumnIndex="1" height='210px' childMapping="subtasks" ref="treegrid" :editSettings="editSettings" :toolbar="toolbar">
<e-columns>
<e-column field="taskID" :isPrimaryKey="true" headerText="Task ID" 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="90" 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-columns>
</ejs-treegrid>
</div>
</div>
</div>
</template>
<script setup>
import { provide, ref } from "vue";
import { TreeGridComponent as EjsTreegrid, Page, Toolbar, Edit,
ColumnDirective as EColumn, ColumnsDirective as EColumns
} from "@syncfusion/ej2-vue-treegrid";
import { ButtonComponent as EjsButton } from "@syncfusion/ej2-vue-buttons";
import { sampleData } from './datasource.js';
const treegrid = ref(null);
const data = sampleData;
const editSettings = { allowAdding:true, allowDeleting:true, allowEditing: true };
const toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
const btnClick = function() {
if (treegrid.value.$el.classList.contains('disabletreegrid')) {
treegrid.value.$el.classList.remove('disabletreegrid');
document.getElementById("TreeGridParent").classList.remove('wrapper');
}
else {
treegrid.value.$el.classList.add('disabletreegrid');
document.getElementById("TreeGridParent").classList.add('wrapper');
}
};
provide('treegrid', [Page, Edit, Toolbar]);
</script>
<style>
.disabletreegrid {
pointer-events: none;
opacity: 0.4;
}
.wrapper {
cursor: not-allowed;
}
</style>
<template>
<div id="app">
<div>
<ejs-button iconCss="e-icons e-play-icon" cssClass="e-flat" :isPrimary="true" :isToggle="true" v-on:click="btnClick">Enable/Disable Grid</ejs-button>
<div id="TreeGridParent">
<ejs-treegrid :dataSource="data" :treeColumnIndex="1" height='210px' childMapping="subtasks" ref="treegrid" :editSettings="editSettings" :toolbar="toolbar">
<e-columns>
<e-column field="taskID" :isPrimaryKey="true" headerText="Task ID" 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="90" 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-columns>
</ejs-treegrid>
</div>
</div>
</div>
</template>
<script>
import { TreeGridComponent, Page, Toolbar, Edit, ColumnDirective, ColumnsDirective } from "@syncfusion/ej2-vue-treegrid";
import { ButtonComponent } from "@syncfusion/ej2-vue-buttons";
import { sampleData } from './datasource.js';
export default {
name: "App",
components: {
"ejs-button":ButtonComponent,
"ejs-treegrid":TreeGridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
},
data() {
return {
data: sampleData,
editSettings: { allowAdding:true, allowDeleting:true, allowEditing: true },
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel']
};
},
methods: {
btnClick() {
if (this.$refs.treegrid.$el.classList.contains('disabletreegrid')) {
this.$refs.treegrid.$el.classList.remove('disabletreegrid');
document.getElementById("TreeGridParent").classList.remove('wrapper');
}
else {
this.$refs.treegrid.$el.classList.add('disabletreegrid');
document.getElementById("TreeGridParent").classList.add('wrapper');
}
}
},
provide: {
treegrid: [Page, Edit, Toolbar]
}
}
</script>
<style>
.disabletreegrid {
pointer-events: none;
opacity: 0.4;
}
.wrapper {
cursor: not-allowed;
}
</style>