|
App.vue
<ejs-grid ref="grid" :dataSource='data' height="400" width="800" :frozenColumns="2" :enableVirtualization="true"
:dataStateChange='dataStateChange' :rowSelected="rowSelected" :allowSorting="true" :rowHeight="30" :allowResizing="true" >
<e-columns>
<e-column field= "OrderID" headerText="Order ID" width="130" textAlign='Right' ></e-column>
<e-column field= "CustomerID" headerText="CustomerID" width="130" textAlign='Right' ></e-column>
<e-column field= "Freight" headerText="Freight" width="130" textAlign='Right' ></e-column>
<e-column field= "ShipCountry" headerText="Country" width="130" textAlign='Right' ></e-column>
<e-column field= "ShipCity" headerText="City" width="130" textAlign='Right' ></e-column>
<e-column field= "ShipAddress" headerText="Address" width="130" textAlign='Right' ></e-column>
</e-columns>
</ejs-grid>
dataStateChange: function (state) {
if (state.action && (state.action.requestType === "filterchoicerequest" || state.action.requestType ==="filtersearchbegin")) {
this.orderService.execute(state).then((e) => {
state.dataSource(e.result);
});
} else {
this.orderService.execute(state).then(( gridData ) => this.data = gridData );
}
|
|
<template>
<div id="app">
<ejs-grid
id="Grid"
ref="grid"
height="400"
:dataSource="data"
:frozenColumns="3"
:enableVirtualization="true"
:columns="columns"
:load="load"
></ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Freeze, VirtualScroll } from "@syncfusion/ej2-vue-grids";
import { DataUtil } from "@syncfusion/ej2-data";
import { data } from "./datasource";
import { CheckBoxPlugin } from "@syncfusion/ej2-vue-buttons";
import { enableRipple } from "@syncfusion/ej2-base";
enableRipple(true);
Vue.use(GridPlugin);
Vue.use(CheckBoxPlugin);
export default {
data() {
return {
data: DataUtil.parse.parseJson(data),
columns: [
{ field: "OrderID", width: "140" },
{ field: "CustomerID", width: "140" },
{ field: "OrderDate", format: "yMd", width: "140" },
{ field: "Freight", format: "C2", width: "140" },
{ field: "ShipCountry", width: "140" }
]
};
e;
},
provide: {
grid: [VirtualScroll, Freeze]
},
methods: {
load: function(args) {
// add the custom column if it not present in the grid column
if (!( this.$refs.grid.$el.ej2_instances[0].columns[0].field === "customcolumn" )){
// add a custom column into the grid columns
this.$refs.grid.$el.ej2_instances[0].columns.unshift({
field: "customcolumn",
headerText: "Visible",
width: "90",
template: this.gridSearchTemplate // bind the template for that column
});
}
},
gridSearchTemplate: function() {
return {
template: Vue.component("GridSearchTemplate", {
template: `
<div ><ejs-checkbox :change="checkboxChange"></ejs-checkbox> // render a checkbox component
</div>`,
data() {
return {};
},
methods: {
checkboxChange: function(args) {
// this event will be triggered when checkbox state changed
// here you can do your action
}
}
})
};
}
}
};
</script>
|
|
vue.config.js
module.exports = {
configureWebpack: {
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js' // 'vue/dist/vue.common.js' for webpack 1
}
}
}
} |
|
<template>
<div id="app">
<ejs-grid
id="Grid"
ref="grid"
height="400"
:dataSource="data"
:frozenColumns="3"
:enableVirtualization="true"
:recordClick="recordClick"
:columns="columns"
></ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Freeze, VirtualScroll } from "@syncfusion/ej2-vue-grids";
import { DataUtil } from "@syncfusion/ej2-data";
import { data } from "./datasource";
import { CheckBoxPlugin } from "@syncfusion/ej2-vue-buttons";
import { enableRipple } from "@syncfusion/ej2-base";
enableRipple(true);
Vue.use(GridPlugin);
Vue.use(CheckBoxPlugin);
export default {
data() {
return {
data: DataUtil.parse.parseJson(data),
columns: [
{ field: "OrderID", isPrimaryKey: true, width: "140" },
{ field: "CustomerID", width: "140" },
{ field: "OrderDate", format: "yMd", width: "140" },
{ field: "Freight", format: "C2", width: "140" },
{ field: "ShipCountry", width: "140" }
]
};
},
provide: {
grid: [VirtualScroll, Freeze]
},
methods: {
recordClick: function(args) {
console.log(args);
// here we are changing the ‘CustomerID’ column’s value
args.rowData.CustomerID = "changed";
setTimeout((e)=>{
// here invoking the setRowData method of the Grid
this.$refs.grid.ej2Instances.setRowData(args.rowData["OrderID"], args.rowData);
},)
}
}
};
</script> |