<template>
<div id="app">
<div>
<ejs-grid ref="grid" id="grid" :dataSource="data" :allowSorting=true :actionBegin="actionBegin">
<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" width="120" format="C2"></e-column>
</e-columns>
</ejs-grid>
</div>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Page, Sort } from "@syncfusion/ej2-vue-grids";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
import {gridData} from './data'
Vue.use(ButtonPlugin);
Vue.use(GridPlugin);
export default {
data() {
return {
data: gridData
};
},
methods: {
actionBegin: function(args) {
if (args.requestType === "sorting") {
console.log(args);
// here we can catch the event while clicking the headercell
alert(args.columnName + ':' + args.direction);
}
}
},
provide: {
grid: [Page, Sort]
}
};
</script>
|
<template>
<div id="app">
<ejs-grid ref="grid" :dataSource="data" :allowSorting="true" :allowPaging="true" height="273px">
<e-columns>
<e-column field="no" headerText="Sort column" textAlign="Right" width="100"></e-column>
<e-column
field="name"
:headerTemplate="cTemplate"
:allowSorting="false"
headerText="Name"
width="120"
></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import {
GridPlugin,
Page,
Filter,
Sort,
Toolbar,
Edit
} from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
Vue.use(GridPlugin);
export default {
data() {
return {
data: [
{ no: 1, name: "Value1" },
{ no: 2, name: "Value2" },
{ no: 3, name: "Value3" }
],
cTemplate: function() {
return {
template: Vue.component("columnTemplate", {
template: `<div v-on:click="headerclicked($event,data)" class="headertemplate" style="color:red">
Field No
</div>`,
data: function() {
return {
data: {}
};
},
computed: {},
methods: {
headerclicked: function(e, data) {
console.log(e, data);
// here you can perform your actions
alert(data.field+ " " + "Clicked");
}
}
})
};
}
};
},
provide: {
grid: [Page, Filter, Sort, Edit, Toolbar]
}
};
</script>
<style>
@import "https://cdn.syncfusion.com/ej2/material.css";
</style> |
cTemplate: function() {
return {
template: Vue.component("columnTemplate", {
template: `<div v-on:click="headerclicked($event,data).bind(this)" style="color:red" class="headertemplate">
// here we can show the headertext
{{data.headerText}}
</div>`,
data: function() {
return {
data: {}
};
},
|
<template>
<div id="app">
<ejs-grid
ref="grid"
:destroyed="destroyed"
:load="load"
:dataSource="data"
:allowSorting="true"
:allowPaging="true"
>
<e-columns>
<e-column field="OrderID" headerText="Order ID" width="120" textAlign="Right"></e-column>
<e-column
field="CustomerID"
:headerTemplate="cTemplate"
:allowSorting="false"
headerText="Customer Name"
width="150"
></e-column>
<e-column
field="OrderDate"
:headerTemplate="cTemplate"
:allowSorting="false"
headerText="Order Date"
width="130"
format="yMd"
textAlign="Right"
></e-column>
. . .
></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import {
GridPlugin,
Page,
Filter,
Sort,
Toolbar,
Edit
} from "@syncfusion/ej2-vue-grids";
Vue.use(GridPlugin);
//initialize the eventhub
Vue.prototype.$eventHub = new Vue();
export default {
data() {
return {
data: [
. . .
],
cTemplate: function() {
return {
template: Vue.component("columnTemplate", {
template: `<div v-on:click="headerclicked($event,data).bind(this)" style="color:red" class="headertemplate">
{{data.headerText}}
</div>`,
data: function() {
return {
data: {}
};
},
computed: {},
methods: {
headerclicked: function (e, data) {
console.log(e, data);
alert("From HeaderTemplate" + data.field + " " + "Clicked");
// here emitting the values when the header is clicked
this.$eventHub.$emit("template", data);
}
}
})
};
}
};
},
methods: {
// here we can listen the values when the header is clicked
getTemplateValue: function(e) {
alert("From root" + e.field + " " + "Clicked");
//here you can perform your actions
},
load: function() {
//adding listener
this.$eventHub.$on("template", this.getTemplateValue);
},
destroyed: function() {
//removing listener
this.$eventHub.$off("template", this.getTemplateValue);
}
},
provide: {
grid: [Page, Filter, Sort, Edit, Toolbar]
}
};
</script>
<style>
@import "https://cdn.syncfusion.com/ej2/material.css";
</style>
|