
// Button template
export const deleteTemplate = function () {
return {
template: Vue.component('deleteTemplate', {
template: '<ejs-button class="btn btn-default" @click="deleteItem">Remove</ejs-button>',
data: function () {
return {
data: {}
}
},
methods: {
deleteItem () {
console.log('deleteItem', this.data)
}
}
})
}
}
<ejs-grid height="300" :dataSource="managedBpList" ref="managedBp"
@rowSelected="selectedManaged">
<e-columns>
<e-column field="bpCd" headerText="코드"></e-column>
<e-column field="bpNm" headerText="가맹점"></e-column>
<e-column field="bpSttusNm" headerText="상태"></e-column>
<e-column field="bpCd" headerText="삭제" :template="deleteTemplate"></e-column>
</e-columns>
</ejs-grid>
|
<template>
<div id="app">
<ejs-grid
ref="grid"
:dataSource="data"
:editSettings="editSettings"
:commandClick="commandClick"
height="310px"
>
<e-columns>
<e-column field="Commands" headerText="Commands" width="150" :commands="commands"></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import {
GridPlugin,
Page,
Toolbar,
Edit,
CommandColumn
} from "@syncfusion/ej2-vue-grids";
import { closest } from "@syncfusion/ej2-base";
import { data } from "./datasource.js";
Vue.use(GridPlugin);
export default {
data() {
return {
data: data,
editSettings: { allowEditing: true, allowDeleting: true },
commands: [
{
buttonOption: { content: "Details", cssClass: "e-flat custombutton" }
} // bind the button here
]
};
},
provide: {
grid: [Page, Edit, Toolbar, CommandColumn]
},
methods: {
commandClick: function(args) {
// event will be triggered when we click the command column button
if (args.target.classList.contains("custombutton")) {
// here you can perform the action as you want
console.log(args);
alert(JSON.stringify(args.rowData));
}
}
}
};
</script>
<style>
@import "https://cdn.syncfusion.com/ej2/material.css";
</style>
|
|
[App.vue]
<template>
<div id="app">
<ejs-grid
ref="grid"
:dataSource="data"
:editSettings="editSettings"
:commandClick="commandClick"
height="310px"
>
<e-columns>
----
<e-column
field="Commands"
headerText="Commands"
width="150"
:commands="commands"
></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
----
export default {
data() {
return {
data: data,
editSettings: { allowEditing: true, allowDeleting: true },
commands: [
{
buttonOption: { content: "Details", cssClass: "custombutton e-info" },
},
],
};
},
provide: {
grid: [Page, Edit, Toolbar, CommandColumn],
},
methods: {
commandClick: function (args) {
if (args.target.classList.contains("custombutton")) {
console.log(args);
alert(JSON.stringify(args.rowData));
}
},
},
};
</script>
<style>
</style>
|
|
[App.vue]
<template>
<div id="app">
<ejs-grid
ref="grid"
:dataSource="data"
:editSettings="editSettings"
:commandClick="commandClick"
height="310px"
>
<e-columns>
----
<e-column
field="Commands"
headerText="Commands"
width="150"
:commands="commands"
></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
------
export default {
data() {
return {
data: data,
editSettings: { allowEditing: true, allowDeleting: true },
commands: [
{
buttonOption: { content: "Details", cssClass: "custombutton" },
},
],
};
},
provide: {
grid: [Page, Edit, Toolbar, CommandColumn],
},
methods: {
commandClick: function (args) {
if (args.target.classList.contains("custombutton")) {
console.log(args);
alert(JSON.stringify(args.rowData));
}
},
},
};
</script>
<style>
.custombutton,
.custombutton:hover,
.custombutton:focus,
.custombutton:active {
background-color: #0000FF;
color: #fff;
}
</style>
|
|
[app.vue]
commandClick: function (args) {
if (args.target.classList.contains("custombutton")) {
// get the row details by passing the td element in the getRowInfo method
var rowInfo = this.$refs.grid.$el.ej2_instances[0].getRowInfo(args.target.closest("td"));
console.log(rowInfo);
alert("rowIndex - " + rowInfo.rowIndex);
}
}
|
|
commands: [
{
buttonOption: { content: "Details", cssClass: "custombutton e-round-corner e-info" },
},
],
CSS:
<style>
.e-round-corner {
border-radius: 10px;
}
</style>
|