Enable disable grid and its actions in Vue Grid component
16 Mar 20235 minutes to read
You can enable/disable the Grid and its actions by applying/removing corresponding CSS styles.
To enable/disable the grid and its actions, follow the given steps:
Step 1:
Create CSS class with custom style to override the default style of Grid.
.disablegrid {
pointer-events: none;
opacity: 0.4;
}
.wrapper {
cursor: not-allowed;
}
Step 2:
Add/Remove the CSS class to the Grid in the click event handler of Button.
btnClick(args) {
if (this.$refs.Grid.$el.classList.contains('disablegrid')) {
this.$refs.Grid.$el.classList.remove('disablegrid');
document.getElementById("GridParent").classList.remove('wrapper');
}
else {
this.$refs.Grid.$el.classList.add('disablegrid');
document.getElementById("GridParent").classList.add('wrapper');
}
}
In the below demo, the button click will enable/disable the 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.native="btnClick">Enable/Disable Grid</ejs-button>
<div id="GridParent">
<ejs-grid ref='Grid' :dataSource='data' :editSettings='editSettings' :toolbar='toolbar' height='273px'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' :isPrimaryKey='true' width=100></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=120></e-column>
<e-column field='Freight' headerText='Freight' textAlign= 'Right' editType= 'numericedit' width=120 format= 'C2'></e-column>
<e-column field='ShipCountry' headerText='Ship Country' editType= 'dropdownedit' width=150></e-column>
</e-columns>
</ejs-grid>
</div>
</div>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Page, Toolbar, Edit } from "@syncfusion/ej2-vue-grids";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
import { data } from './datasource.js';
Vue.use(GridPlugin);
Vue.use(ButtonPlugin);
export default {
data() {
return {
data: data,
editSettings: { allowAdding:true, allowDeleting:true, allowEditing: true },
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel']
};
},
methods: {
btnClick(args) {
if (this.$refs.Grid.$el.classList.contains('disablegrid')) {
this.$refs.Grid.$el.classList.remove('disablegrid');
document.getElementById("GridParent").classList.remove('wrapper');
}
else {
this.$refs.Grid.$el.classList.add('disablegrid');
document.getElementById("GridParent").classList.add('wrapper');
}
}
},
provide: {
grid: [Page, Edit, Toolbar]
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material.css";
.disablegrid {
pointer-events: none;
opacity: 0.4;
}
.wrapper {
cursor: not-allowed;
}
</style>