I have a simple Vue.js grid and am binding the data myself. The grid is set up to be editable. Everything works perfect and I am able to edit records and (independently) update the data to the server. However, when I try to sort, filter or paginate the table, a spinner is created and processing stops - no errors are written to the console.
Here is my simplified code:
<template>
<content-container>
<template slot="header">
<v-layout
v-bind="rowMdAndUp"
class="header elevation-1"
:style="lightBackgroundColor">
<v-flex>
<span class="header-text">Sample</span>
</v-flex>
</v-layout>
</template>
<div>
<v-card flat>
<ejs-grid
:ref="refgrid"
id="refgrid"
width="100%"
:allowExcelExport="true"
:allowFiltering="true"
:allowGrouping="true"
:allowMultiSorting="true"
:allowPaging="true"
:allowReordering="true"
:allowResizing="true"
:allowSorting="true"
:dataSource="{ result: this.sampleData, count: this.sampleData.length }"
:disablePageWiseAggregates="false"
:filterSettings="filterSettings"
:groupSettings="groupSettings"
:pageSettings="pageSettings"
:showColumnChooser="true"
:showColumnMenu="false"
:toolbar="toolbarOptions"
:allowTextWrap="true"
:textWrapSettings="{wrapMode: 'Header'}"
:editSettings="editSettings"
:dataSourceChanged="dataSourceChanged"
:actionComplete="actionComplete"
>
<e-columns>
<e-column field='id' headerText='Id' :visible=false :showInColumnChooser='false' :isPrimaryKey='true'></e-column>
<e-column field='firstName' headerText='First Name'></e-column>
<e-column field='lastName' headerText='Last Name'></e-column>
<e-column field='initials' headerText='Initials'></e-column>
</e-columns>
</ejs-grid>
</v-card>
</div>
</content-container>
</template>
<script>
import { mapGetters } from 'vuex';
import Vue from 'vue';
import { rowMdAndUp, backgroundColor } from '@/mixins';
import ContentContainer from './../../../components/ContentContainer';
import { Toolbar, ExcelExport, Group, ColumnChooser, Filter, Resize, Sort, Page, Reorder, GridPlugin, Edit } from '@syncfusion/ej2-vue-grids';
Vue.use(GridPlugin);
export default {
provide: {
grid: [ Toolbar, ExcelExport, Group, ColumnChooser, Filter, Resize, Sort, Page, Reorder, Edit ]
},
name: 'Sample',
mixins: [rowMdAndUp, backgroundColor],
components: { ContentContainer },
computed: {
...mapGetters({
processing: 'dataExtract/processing'
}),
grid() {
return this.$refs['refgrid'];
}
},
data() {
return {
buttonHidden: false,
shouldDisable: false,
filterSettings: { type: 'Excel' },
groupSettings: { showGroupedColumn: true },
needsColumnsAdjusted: false,
pageSettings: { pageSizes: true, pageSize: 20 },
toolbarOptions: ['ExcelExport', 'Add', 'Edit', 'Update', 'Cancel', 'ColumnChooser'],
sampleData: [],
refgrid: 'refgrid',
editSettings: { allowEditing: true, allowAdding: true, mode: 'Dialog' }
};
},
created() {
this.getSampleData();
},
methods: {
dataSourceChanged(args) {
console.log(`Entering dataSourceChanged ${args.requestType}`);
if (args.requestType === 'save') {
this.editEvent = args;
this.updateData(args.data);
}
},
actionComplete(args) {
console.log(`Entering actionComplete ${args.requestType}`);
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
let dialog = args.dialog;
dialog.header = args.requestType === 'beginEdit' ? `${args.rowData['firstName']} ${args.rowData['lastName']}` : 'New Record';
}
console.log(`Exiting actionComplete ${args.requestType}`);
},
updateData(record) { // Make a call to the server to update the record, handle the result with either endEdit or cancelEdit
console.log('Entering updateData', record);
this.editEvent.endEdit();
},
getSampleData() {
// Get the data from the server
this.sampleData = [
{ 'id': 1, 'firstName': 'f1', 'lastName': 'l1', 'initials': 'i1' },
{ 'id': 2, 'firstName': 'f2', 'lastName': 'l2', 'initials': 'i2' },
{ 'id': 3, 'firstName': 'f3', 'lastName': 'l3', 'initials': 'i3' }
];
}
}
};
</script>
<style lang="scss" scoped>
@import '../../../../node_modules/@syncfusion/ej2-vue-grids/styles/material.css';
</style>
Curiously, if I change the datasource to simply the data array as such:
:dataSource="this.sampleData"
then the data state functions (sort/filter/paginate) work great, but the dataSourceChanged event is no longer triggered.
Thank you for your response. I tried the dataStateChange event, it never fired. Also changing the dataSource to simply this.sampleData causes the filter/sort/pagination to work okay (even without me doing anything), but the dataSourceChanged no longer fires.
New code below. Thanks!
My goal is to have an event triggered when the user clicks save on the dialog that opens so that I can make my calls to update the data on the server. Using
:dataSource="{ result: this.sampleData, count: this.sampleData.length }"achieves this with the dataSourceChanged event. Everything was good but then I tested the sorting and that failed. Switching to the JSON method of binding the data fixed the sorting problem, but now I cannot find an event to fire when the SAVE is clicked.
Using
:dataSource="{ result: this.sampleData, count: this.sampleData.length }"
I was able to get rid of the spinner and change the cursor using some DOM manipulation, but that does not seem like Syncfusions intention to make the developer do that. Either way I am okay with that -- if you could send direction on how to do pagination manually, I can work with this band-aid code.