|
<div>
<e-columns>
<e-column
headerText="Employee Image"
width="150"
textAlign="Center"
:template="cTemplate"
></e-column>
...
</e-columns>
<script>
var itemVue = Vue.component("itemTemplate", {
template: `<span>hi</span>`,
data() {
return {
data: {},
};
},
});
export default Vue.extend({
data: () => {
let secondChildGrid = {
dataSource: customerData,
queryString: "CustomerID",
columns: [
{
headerText: "Custom template",
textAlign: "Right",
template: function () {
return {
template: itemVue,
};
},
width: 75,
},
...
],
childGrid: {
dataSource: hierarchyOrderdata,
queryString: "CustomerID",
columns: [
{
headerText: "Custom template",
textAlign: "Right",
template: function () {
return {
template: itemVue,
};
},
};
return {
parentData: employeeData.slice(0, 5),
cTemplate: function () {
return {
template: Vue.component("columnTemplate", {
template: `<div class="image">
hi
</div>`,
data: function () {
return {
data: {},
};
},
computed: {
image: function () {
return "./" + this.data.EmployeeID + ".png";
},
altImage: function () {
return this.data.EmployeeID;
},
childGrid: {
dataSource: orderDatas,
queryString: "EmployeeID",
columns: [
{
headerText: "Custom template",
template: function () {
return {
template: itemVue,
};
},
},
...
],
childGrid: secondChildGrid,
},
});
</script>
|
|
<template>
<div class="col-lg-12 control-section">
<div>
<ejs-grid
:dataSource="parentData"
:childGrid="childGrid"
:allowSorting="true"
:created="created"
>
</ejs-grid>
</div>
</div>
</template>
<script>
import Vue from "vue";
import {
GridPlugin,
DetailRow,
Sort,
parentsUntil,
} from "@syncfusion/ej2-vue-grids";
Vue.prototype.$eventHub = new Vue();
Vue.use(GridPlugin);
export default Vue.extend({
data: () => {
let secondChildGrid = {
dataSource: customerData,
queryString: "CustomerID",
columns: [
{
headerText: "Custom template",
textAlign: "Right",
template: function () {
return {
template: itemVue,
};
},
width: 75,
},
{
field: "CustomerID",
headerText: "Customer ID",
textAlign: "Right",
width: 75,
},
{ field: "Address", headerText: "Address", width: 120 },
{ field: "Country", headerText: "Country", width: 100 },
],
childGrid: {
dataSource: hierarchyOrderdata,
queryString: "CustomerID",
columns: [
{
headerText: "Custom template",
textAlign: "Right",
template: function () {
return {
template: itemVue,
};
},
width: 75,
},
{
field: "OrderID",
headerText: "Customer ID",
textAlign: "Right",
width: 75,
},
{ field: "ShipCountry", headerText: "Country", width: 100 },
],
},
};
return {
parentData: employeeData.slice(0, 5),
cTemplate: function () {
return {
template: Vue.component("columnTemplate", {
template: `<div class="image">
hi
</div>`,
data: function () {
return {
data: {},
};
},
computed: {
image: function () {
return "./" + this.data.EmployeeID + ".png";
},
altImage: function () {
return this.data.EmployeeID;
},
},
}),
};
},
childGrid: {
dataSource: orderDatas,
queryString: "EmployeeID",
allowPaging: true,
pageSettings: { pageSize: 6, pageCount: 5 },
columns: [
{
headerText: "Custom template",
template: function () {
return {
template: itemVue,
};
},
textAlign: "Right",
width: 120,
},
{
field: "OrderID",
headerText: "Order ID",
textAlign: "Right",
width: 120,
},
{ field: "ShipCity", headerText: "Ship City", width: 120 },
{ field: "Freight", headerText: "Freight", width: 120 },
{ field: "ShipName", headerText: "Ship Name", width: 150 },
],
childGrid: secondChildGrid,
},
};
},
methods: {
created: function (args) {
//here we are listening the event
this.$eventHub.$on("communicate", this.getRowDetails);
},
getRowDetails: function (e) {
// here we can get the row details
console.log(e);
},
},
provide: {
grid: [DetailRow, Sort],
},
});
var itemVue = Vue.component("itemTemplate", {
template: `<span v-on:click="handleClick($event)">hi</span>`,
data() {
return {
data: {},
};
},
methods: {
handleClick: function (args) {
// here we are obtaining the grid instance dynamically based on the target
var grid = parentsUntil(args.target, "e-grid").ej2_instances[0];
// getting the row details
var rowInfo = grid.getRowInfo(args.target);
// emitting the row details
this.$eventHub.$emit("communicate", rowInfo);
},
},
});
</script> |