App.vue
<template>
<div class="col-lg-12 control-section">
<div>
<ejs-grid
ref="grid"
id="gridcomp"
. . .
:contextMenuItems="contextMenuItems"
:contextMenuOpen="contextMenuOpen"
:editSettings="editing"
>
. . .
</ejs-grid>
</div>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, ContextMenu } from "@syncfusion/ej2-vue-grids";
import { data } from "./data";
Vue.use(GridPlugin);
export default Vue.extend({
data: () => {
return {
data: data,
contextMenuItems: [
{
text: "Custom1",
target: ".e-content",
id: "custom"
},
{
text: "Custom2",
target: ".e-content",
id: "custom2"
}
],
editing: { allowDeleting: true, allowEditing: true }
};
},
methods: {
contextMenuOpen: function(args) {
// you can get the rowData in contexMenu open event args also
var contextMenuObj = this.$refs.grid.ej2Instances.contextMenuModule
.contextMenu; //getting the contextMenu instance
if (args.rowInfo.rowData.OrderID % 2 === 0) { //here you can apply your own conditions as per your requirement
contextMenuObj.enableItems(["Custom1"], false);
contextMenuObj.hideItems(["Custom2"]);
} else {
contextMenuObj.enableItems(["Custom1"], true);
contextMenuObj.showItems(["Custom2"]);
}
},
contextMenuClick: function(args) {
if (args.item.id === "custom") {
args.item.text = "changed";
}
}
},
provide: {
grid: [ContextMenu]
}
});
</script> |