Hello,
I have great difficulty having the datagrid work with custom binding.
For each add/edit/delete action in the grid, I have a crud-like api call which was tested against Postman.
Data comes back using result/count.
I am using the DataSourceChanged event like this :
let state = { skip: 0, take: 10 }
/////
dataStateChange(state) {
//load data from backend
this.dataviewservice.getPagedData('cars', state).then((data) => {
this.gridData = data
})
},
onDataSourceChanged(state) {
console.log(state)
if (state.action==='add') {
this.dataviewservice.addData('cars', state)
.then(() => {
console.log('Car added successfully')
state.endEdit()
})
} else if (state.action==='edit') {
this.dataviewservice.updateData('cars', state)
.then(() => {
console.log('Car updated successfully')
state.endEdit()
})
} else if (state.requestType==='delete') {
this.dataviewservice.deleteData('cars', state)
.then(() => {
console.log('Car deleted successfully')
state.endEdit()
})
}
},
All three actions are performed correctly on the server side.
The Edit returns instantly but Add and Delete have the spinner hanging.
Please provide a full sample for Vue 3 DataGrid custom binding.
Thank you
|
// Grid’s dataStateChange event handler
dataSourceChanged: function (state) {
if (state.action === 'add') {
addOrder(state.data).then(() => state.endEdit());
} else if (state.action === 'edit') {
updateOrder(state.data).then(() => { state.endEdit() });
} else if (state.requestType === 'delete') {
deleteOrder(state.data[0].OrderID).then(() => state.endEdit());
}
} |
Hello,
Thank you for this long explanation. I eventually managed to get this working.
Based on the same sample, how should I do to have one my columns as a foreign key ?
I would like to have the foreign values be fetched through an API. I have played around with column datasource, edit property, refreshColumns, etc... In all situations, I have the foreign value displayed correctly, but the dropdownlist in edit mode is never populated.
I have also filed the same issue today on a sample you had provided for a similar React issue.
Thanks,
Julien
Hi,
Thanks to your reply to a similar question in React forum, this is solved by using the following code:
this.$refs.theGrid.getColumnByField('constituentId').dataSource = ds
this.$refs.theGrid.getColumnByField('constituentId').edit.params.dataSource = ds
this.$refs.theGrid.refreshColumns()Julien
|
<template>
<div id="grid_parent">
<ejs-grid
ref="grid"
id="transaction_grid"
:dataSource="data"
allowPaging='true'
:dataSourceChanged="dataSourceChanged"
:dataStateChange="dataStateChange"
:columnDataStateChange='columnStateChange'
:editSettings="editSettings"
:toolbar='toolbar'
>
<e-columns>
. . . . . . . . .
. . . . . . . . .
<e-column field= "EmployeeID" headerText="Employee ID" foreignKeyValue="FirstName" :dataSource="colData" width="150"></e-column>
. . . . . . . . .
. . . . . . . . .
</e-columns>
</ejs-grid>
</div>
</template>
<style>
</style>
<script>
import Vue from "vue";
import { GridPlugin, Page, Toolbar, Edit, ForeignKey } from "@syncfusion/ej2-vue-grids";
import { getOrders, addOrder, updateOrder, deleteOrder } from "./orderService";
import { EmployeeService } from "./EmployeeService";
Vue.use(GridPlugin);
export default {
name: 'app',
data() {
return {
data: {},
colData: {},
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true },
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
employeeService: new EmployeeService(),
};
},
mounted() {
let state = { skip: 0, take: 12 };
this.dataStateChange(state);
this.columnStateChange({setColumnData:this.$refs.grid.ej2Instances.setForeignKeyData.bind(this.$refs.grid.ej2Instances)})
},
methods: {
dataStateChange: function (state) {
getOrders().then(gridData => {
this.data = gridData;
}
);
},
columnStateChange: function (state) {
this.employeeService.execute(state).then(( gridData ) => {
console.log(gridData);
//instance.ref.grid.columns[1].dataSource = gridData;
this.colData = gridData;
state.setColumnData();
} );
},
dataSourceChanged: function (state) {
if (state.action === 'add') {
addOrder(state.data).then(() => state.endEdit());
} else if (state.action === 'edit') {
updateOrder(state.data).then(() => { state.endEdit()});
} else if (state.requestType === 'delete') {
deleteOrder(state.data[0].OrderID).then(() => state.endEdit());
}
}
},
provide: {
grid: [Page, Toolbar, Edit, ForeignKey],
},
}
</script>
|