<template>
<div class="app-container">
<div id="Grid">
</div>
</div>
</template>
<script>
import { fetchList, deleteDevice,fetchPropertiesAPI } from "@/api/device";
import { GridPlugin,Grid,Page,Sort,Filter,Group,Toolbar,Search,PdfExport,ExcelExport,CommandColumn } from "@syncfusion/ej2-vue-grids";
import { L10n, setCulture } from '@syncfusion/ej2-base';
setCulture('pt-BR');
L10n.load({
'pt-BR': {
'grid': {
'EmptyRecord': 'Nenhum registro localizado.',
'GroupDropArea': 'Arraste um cabeçalho de coluna aqui para agrupar sua coluna',
'UnGroup': 'Clique oara desagrupar',
'EmptyDataSourceError': 'O DataSource não deve estar vazio no primeiro carregamento, como colunas do dataSource na grade de colunas AutoGenerate',
'Item': 'Item',
'Items': 'Itens'
},
'pager':{
'currentPageInfo': '{0} de {1} páginas.',
'totalItemsInfo': '({0} Total de registros).',
'firstPageTooltip': 'Para a primeira página.',
'lastPageTooltip': 'Para a última página.',
'nextPageTooltip': 'Para a próxima página.',
'previousPageTooltip': 'Voltar para última página.',
'nextPagerTooltip': 'Para a próxima página.',
'previousPagerTooltip': 'Para a página anterior.'
}
}
});
export default {
name: 'DeviceList',
components: { },
data() {
return {
data: {},
selectedRow: 0,
list: "",
displayFields: "",
grid: new Grid(),
pageOptions: { pageSize: 5, pageSizes: true },
listQuery: {
page: 1,
limit: 20,
offset: 19
}
//DataService: new DataService(),
};
},
mounted() {
// Used vue mounted hook to provide dataSource to Grid and handled the initial paging
let state = { skip: 0, take: this.pageOptions.pageSize };
this.createDataGrid();
//this.dataStateChange(state);
},
methods: {
dataStateChange: function (state) {
// Handled the other Grid actions like paging, sorting etc.. by using dataState change event
this.DataService
.execute(state)
.then((gridData) => (this.data = gridData));
},
createDataGrid: function () {
Grid.Inject(
Page,
Sort,
Filter,
Group,
Toolbar,
Search,
PdfExport,
ExcelExport,
CommandColumn
);
this.grid = new Grid({
width: '100%',
pageSettings: { pageSize: 50 },
allowEditing: true,
allowAdding: true,
allowDeleting: true,
allowSorting: true,
allowGrouping: true,
allowTextWrap: true,
allowPaging: true,
allowExcelExport: false,
allowPdfExport: false,
filterSettings:'filterOptions',
selectionOption: {type: 'Single'},
toolbarClick: function (args) {
this.gridtoolbarClick(args);
}.bind(this),
resizeSettings: { mode: "Normal" },
created: function () {
this.grid.showSpinner();
this.getList();
}.bind(this),
toolbar: [
"Add",
"Edit",
"Delete",
"Search",
"Print",
],
selectionSettings: { type: "Single", cellSelectionMode: 'Box' },
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" },
},
],
dataBound: function (args) {
this.grid.toolbarModule.enableItems( [this.grid.element.id + "_add"], true);
if (this.grid.getSelectedRecords().length < 1) {
this.grid.toolbarModule.enableItems([this.grid.element.id + "_delete"], false);
this.grid.toolbarModule.enableItems( [this.grid.element.id + "_edit"], false);
}
}.bind(this),
rowSelected: function (args) {
if (this.grid.getSelectedRecords().length > 0) {
this.grid.toolbarModule.enableItems([this.grid.element.id + "_delete"], true);
this.grid.toolbarModule.enableItems( [this.grid.element.id + "_edit"], true);
}
}.bind(this),
rowDeselected: function (args) {
if (this.grid.getSelectedRecords().length === 0) {
this.grid.toolbarModule.enableItems([this.grid.element.id + "_delete"], false);
this.grid.toolbarModule.enableItems( [this.grid.element.id + "_edit"], false);
}
}.bind(this),
actionComplete: function (args) {
setTimeout(() => {
var gridObj = document.getElementById("Grid").ej2_instances[0];
if (gridObj.getSelectedRecords().length < 1) {
gridObj.toolbarModule.enableItems([gridObj.element.id + "_delete"], false);
gridObj.toolbarModule.enableItems([gridObj.element.id + "_edit"], false);
}
});
},
});
this.grid.appendTo("#Grid");
},
gridtoolbarClick: function (args) {
var grid = document.getElementsByClassName("e-grid")[0].ej2_instances[0];
var uuid = grid.getSelectedRecords()[0][grid.getPrimaryKeyFieldNames()[0]];
alert(uuid);
if (args.item.id === "Grid_pdfexport") {
// 'Grid_pdfexport' -> Grid component id + _ + toolbar item name
this.grid.pdfExport();
}
else if (args.item.id === 'Grid_excelexport') { // 'Grid_excelexport' -> Grid component id + _ + toolbar item name
this.grid.excelExport();
}
else if (args.item.id === 'Grid_add') { // 'Grid_add' -> Grid component id + _ + toolbar item name
alert("Click Button ADD...");
}
else if (args.item.id === 'Grid_delete' ) { // 'Grid_delete' -> Grid component id + _ + toolbar item name
alert("Click Button DELETE...");
}
else if (args.item.id === 'Grid_edit') { // 'Grid_edit' -> Grid component id + _ + toolbar item name
alert("Click Button DELETE...");
}
},
getList: function () {
fetchList(this.listQuery).then(response => {
var data = response.data.items
this.grid.dataSource = data;
//this.grid.columns[0].visible = false;
//this.grid.columns[0].isprimarykey = true;
})
fetchPropertiesAPI(this.listQuery).then(response => {
var columns = response.data.listviews[0].columns
this.grid.GridGroupDropArea = response.data.listviews[0].titlegrid;
this.grid.columns = columns;
this.grid.columns[0].visible = false;
this.grid.columns[0].isPrimaryKey = true;
this.grid.refreshColumns();
})
},
},
provide: {
grid: [Sort, Group, Page, Filter,Toolbar],
},
}
</script>
<style scoped>
.edit-input {
padding-right: 100px;
}
.cancel-btn {
position: absolute;
right: 15px;
top: 10px;
}
</style>
I 'm migrating my old template form to new form with syncfusion data_grid package.
template>
<div class="app-container">
<el-table
v-loading="listLoading"
:data="list"
border
fit
highlight-current-row
style="width: 100%"
>
<el-table-column align="left" label="UUID" width="285" v-if="false">
<template slot-scope="scope">
<span>{{ scope.row.uuid }}</span>
</template>
</el-table-column> -->
<el-table-column min-width="180px" label="Nome">
<template slot-scope="{ row }">
<router-link :to="'/managerdevice/device/view/' + row.uuid + '/'" class="link-type">
<span>{{ row.name }}</span>
</router-link>
</template>
</el-table-column>
<el-table-column width="250px" align="left" label="Descrição">
<template slot-scope="scope">
<span>{{ scope.row.description }}</span>
</template>
</el-table-column>
<el-table-column class-name="status-col" label="Status" width="80">
<template slot-scope="{ row }">
<el-tag :type="row.islocked | statusFilter">
{{ row.islocked }}
</el-tag>
</template>
</el-table-column>
<el-table-column align="center" label="Ação" width="240">
<template slot-scope="scope">
<router-link :to="'/managerdevice/device/edit/' + scope.row.uuid + '/'">
<el-button
type="primary"
style="margin-left: 10px"
size="mini"
icon="el-icon-edit"
>Alterar
</el-button>
</router-link>
<el-button
type="danger"
style="margin-left: 10px"
size="mini"
icon="el-icon-delete"
@click="handleDelete(scope.row.uuid)"
>Deletar
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
</div>
</template>
See in my new code template, i have three custom button data grid (ADD,EDIT AND DELETE) and ,today, each button open a alert windows examples (alert("Click Button ADD...");).
I want change this row (remove alert msg) and include a other function which open other page after clicked through router url customized by me. Per example: After the user click the Edit Button, i need to open another page whose url router (router_link) below: