|
[vue.js]
<template>
<div id="app">
<ejs-grid
ref="grid"
:dataSource="data"
:detailTemplate="detailTemplate"
:dataBound="dataBound"
:detailDataBound="detailDataBound"
height="273px"
>
----
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import {
GridPlugin,
DetailRow,
Page,
Toolbar,
Edit,
} from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
Vue.use(GridPlugin);
export default {
data() {
return {
data: data,
detailTemplate: function () {
return {
template: Vue.component("detailTemplate", {
// define the empty div
template: `
<div class="detailtable" width="100%">
</div>`,
data: function () {
return {
data: {},
};
},
methods: {},
computed: {},
}),
};
},
};
},
methods: {
dataBound(args) {
// ON the internal event detail-state-change which triggered every time while expanding/collapsing the detail row after initial expand.
this.$refs.grid.$el.ej2_instances[0].on("detail-state-change", function (args) {
// executed when expand/collapse a detail row
var row = args.detailElement.closest("tr").nextElementSibling.querySelector(".detailtable");
if (args.isExpanded) {
// executed when expand a detail row
var detaildata = document.createElement("div");
detaildata.classList.add("detaildata");
detaildata.innerText = "Customer Name: " + args.data.CustomerID + ", Country: " + args.data.ShipCountry;
row.appendChild(detaildata); // append the detail element
} else {
// executed when collapse a detail row
row.querySelector(".detaildata").remove(); // remove the detail element
}
});
},
detailDataBound: function (args) { // executed at initial expand of detail row
var detaildata = document.createElement("div");
detaildata.classList.add("detaildata");
detaildata.innerText = "Customer Name: " + args.data.CustomerID + ", Country: " + args.data.ShipCountry;
args.detailElement.querySelector(".detailtable").appendChild(detaildata); // append the detail element
},
},
provide: {
grid: [Page, Edit, DetailRow, Toolbar],
},
};
</script>
|
Really happy with your help! This is indeed working.When the grid data is refreshed and you open the details again the detail-state-change is fired twice... how can I prevent this?