- Fix Datamanager.init

- Revert oldValue when setValue promise fails
This commit is contained in:
Faris Ansari 2017-11-20 15:57:27 +05:30
parent 3c2c530127
commit 86f9bba5d2
3 changed files with 25 additions and 13 deletions

View File

@ -962,14 +962,17 @@ var CellManager = function () {
if (editing) {
var value = editing.getValue();
var done = editing.setValue(value);
var oldValue = this.getCell(colIndex, rowIndex).content;
// update cell immediately
this.updateCell(rowIndex, colIndex, value);
if (done && done.then) {
// wait for promise then update internal state
done.then(function () {
return _this7.updateCell(rowIndex, colIndex, value);
// revert to oldValue if promise fails
done.catch(function (e) {
console.log(e);
_this7.updateCell(rowIndex, colIndex, oldValue);
});
} else {
this.updateCell(rowIndex, colIndex, value);
}
}
}
@ -1732,7 +1735,6 @@ var DataManager = function () {
_classCallCheck(this, DataManager);
this.options = options;
this.rowCount = 0;
this.currentSort = {
sortBy: -1, // colIndex
sortOrder: 'none' // asc, desc, none
@ -1746,6 +1748,10 @@ var DataManager = function () {
rows = data.rows;
this.rowCount = 0;
this.columns = [];
this.rows = [];
this.columns = this.prepareColumns(columns);
this.rows = this.prepareRows(rows);

View File

@ -412,14 +412,17 @@ export default class CellManager {
if (editing) {
const value = editing.getValue();
const done = editing.setValue(value);
const oldValue = this.getCell(colIndex, rowIndex).content;
// update cell immediately
this.updateCell(rowIndex, colIndex, value);
if (done && done.then) {
// wait for promise then update internal state
done.then(
() => this.updateCell(rowIndex, colIndex, value)
);
} else {
this.updateCell(rowIndex, colIndex, value);
// revert to oldValue if promise fails
done.catch((e) => {
console.log(e);
this.updateCell(rowIndex, colIndex, oldValue);
});
}
}
}

View File

@ -3,7 +3,6 @@ import { isNumeric } from './utils';
export default class DataManager {
constructor(options) {
this.options = options;
this.rowCount = 0;
this.currentSort = {
sortBy: -1, // colIndex
sortOrder: 'none' // asc, desc, none
@ -13,6 +12,10 @@ export default class DataManager {
init(data) {
let { columns, rows } = data;
this.rowCount = 0;
this.columns = [];
this.rows = [];
this.columns = this.prepareColumns(columns);
this.rows = this.prepareRows(rows);