<template>
<div class="app-container">
<div id="Grid">
</div>
</div>
</template>
<script>
import { fetchListAPI,deletePackageAPI,fetchPropertiesAPI } from '@/api/core/package'
import Vue from "vue";
import { GridPlugin,Grid,Page,Sort,Filter,Group,Toolbar,Search,PdfExport,ExcelExport,CommandColumn } from "@syncfusion/ej2-vue-grids";
Vue.use(GridPlugin);
export default {
name: 'PackageList',
components: {
},
data() {
},
data: function() {
return {
selectedRow: 0,
list: "",
displayFields: "",
grid: ""
}
},
provide: {
grid: [Page,Sort,Filter,Group,Toolbar,Search,PdfExport,ExcelExport,CommandColumn]
},
created() {
this.getProperties()
this.getList()
},
mounted() {
this.createDataGrid()
},
methods: {
//dataBound: function() {
// this.$refs.grid.ej2Instances.columns[0].isPrimaryKey = true;
//},
select: function(rec) {
this.selectedRow = rec[this.pkey];
this.$emit("select", rec);
},
// Function Create and Populate Grid Dynamically
createDataGrid: function() {
Grid.Inject(Page,Sort,Filter,Group,Toolbar,Search,PdfExport,ExcelExport,CommandColumn);
this.grid = new Grid({
pageSettings: { pageSize: 50 },
allowEditing: true,
allowAdding: true,
allowDeleting: true,
toolbar: ["Add", "Edit", "Delete", "Search","PdfExport","ExcelExport","Print"],
selectionSettings: { persistSelection: true },
filterOptions: { type: 'Menu', type: 'CheckBox' },
commands: [ { type: 'Edit', buttonOption: { cssClass: 'e-flat', iconCss: 'e-edit e-icons' } },
{ type: 'Delete', buttonOption: { cssClass: 'e-flat', iconCss: 'e-delete e-icons' } },
{ type: 'Save', buttonOption: { cssClass: 'e-flat', iconCss: 'e-update e-icons' } },
{ type: 'Cancel', buttonOption: { cssClass: 'e-flat', iconCss: 'e-cancel-icon e-icons' } }]
});
this.grid.appendTo("#Grid");
this.grid.dataSource = this.list
//console.log(this.grid.dataSource)
this.grid.columns = this.displayFields;
//console.log(this.grid.columns)
this.grid.refreshColumns();
},
// Function Toolbar events Button
toolbarClick(args) {
if (args.item.id === 'Grid_pdfexport') { // 'Grid_pdfexport' -> Grid component id + _ + toolbar item name
this.$refs.grid.pdfExport();
}
else if (args.item.id === 'Grid_excelexport') { // 'Grid_excelexport' -> Grid component id + _ + toolbar item name
this.$refs.grid.excelExport();
}
else if (args.item.id === 'Grid_add') { // 'Grid_add' -> Grid component id + _ + toolbar item name
alert("Clicou botão ADD...");
}
else if (args.item.id === 'Grid_delete' ) { // 'Grid_delete' -> Grid component id + _ + toolbar item name
console.log(args.form.querySelector("uuid").value);
//handleDelete(args.form.querySelector("#Freight"))
}
else if (args.item.id === 'Grid_edit') { // 'Grid_edit' -> Grid component id + _ + toolbar item name
alert("Clicou botão EDIT...");
}
},
commandClick: function(args) {
console.log(args.id)
alert(JSON.stringify(args.rowData));
},
getList: function() {
fetchListAPI(this.listQuery).then(response => {
this.list = response.data.items
})
},
getProperties: function() {
fetchPropertiesAPI(this.listQuery).then(response => {
this.displayFields = response.data.listviews[0].columns
})
},
handleDelete(uuid) {
deleteTier(uuid).then(response => {
this.$notify({
title: 'Mensagem',
message: 'Registro deletado com sucesso',
type: 'success',
duration: 2000
})
this.getList()
}).catch(err => {
console.log(err)
})
}
}
}
</script>
<style scoped>
.edit-input {
padding-right: 100px;
}
.cancel-btn {
position: absolute;
right: 15px;
top: 10px;
}
</style>