Grid.data.save() mode?

How can i get the mode from the data.save(url) function on server (insert,update,delete) ?
it seems there are no mode parameter send ?

Unfortunately, currently, it is not available, but we’re planning to extend that functionality in future updates.

This is a essential method?

Is it a question? Could you please clarify your post.

No, that wasn’t a question.
data.save (url) sends all data to the server by post and there you cannot distinguish between add insert and delete.
I think it would be an important function because it is useless like that.
Or could you explain to me how I can make the distinction?

Unfortunately, currently, it is not available to get the status of the updating item, but we’re planning to extend that functionality in future updates.

suite.js original:

DataProxy.prototype.save = function (data, mode) {
switch (mode) {
case “delete”:
return ajax_1.ajax.delete(this.url, data);
case “update”:
case “insert”:
default:
return ajax_1.ajax.post(this.url, data);
}
};

overload:

dhx.DataProxy.prototype.save = function (data, mode) {
//console.log(“NEW Save”, mode, data);
let $mode = null;
switch (mode) {
case “insert”:
case “add”:
$mode = “insert”;
break;
case “update”:
$mode = “update”;
break;
case “remove”:
case “delete”:
$mode = “delete”;
break;
default:
console.warn(“DataProxy save Unknown mode:”, mode);
}
data.$mode = $mode;
return dhx.ajax.post(this.url, data).then(function (result) {
//console.log("NEW Save Post " + mode, result);
return result;
});
};

in your app.js, check always if issaved false otherwise without changes you get a then is undefined error !

if (!grid.data.isSaved()) {
grid.data.save(this.dataUrl);
grid.data.saveData.then(function (result) {
console.log(“result:”, result);
console.log(“Data has been saved”);
};
};

here a sample from nodejs server side with tingodb;

module.exports.postDataDataset = async function (req, res, db) {
console.log(“POST Params:”, req.params, “POST Body:”, req.body);
let _tbl = db[_tblName];
let _item = req.body;
let _mode = _item.$mode;
console.log(“mode:”, _mode, “item:”, _item);
// delete unused from item
delete _item.$mode;
delete _item.$height;
console.log(“mode:”, _mode, “item cleared:”, _item);
function update_response(error, result) {
console.log(“Error response:”, error, “Result response:”, result);
res.status(201).json({
mode: _mode,
id: _item.id,
error: error,
result: result
});
};
_numericFields.forEach(function (field, index) {
_item[field] = _asutil.Numeral.formatNumericFromLocale2Value(_item[field]);
});
_datetimeFields.forEach(function (field, index) {
_item[field] = _asutil.Luxon.formatDateTimeFromLocale2ISO(_item[field]);
});
_dateFields.forEach(function (field, index) {
_item[field] = _asutil.Luxon.formatDateFromLocale2ISO(_item[field]);
});
_timeFields.forEach(function (field, index) {
_item[field] = _asutil.Luxon.formatTimeFromLocale2ISO(_item[field]);
});
switch (_mode) {
case ‘insert’:
console.log(’=> MODE insert’, _mode);
await _tbl.insert(_item, update_response);
break;
case ‘update’:
await _tbl.findOne({ id: _item.id }, function (error, record) {
console.log(“Error find:”, error, “Record find:”, record);
if (record) {
console.log(’=> MODE update’, ‘update’);
_tbl.update({
id: _item.id
}, _item, update_response);
} else {
console.log(’=> MODE update’, ‘insert’);
_tbl.insert(_item, update_response);
};
});
break;
case ‘delete’:
console.log(’=> MODE delete’, _mode);
await _tbl.remove({
id: _item.id
}, 1, update_response);
break;
default:
console.warn(“Post " + _tbl.collectionName + " Unknown mode:”, _mode);
update_response("Post " + _tbl.collectionName + " Unknown mode: " + _mode, 0);
}
};

1 Like

In the latest dhx.Suite update (7.2) we have updated the save() method:

Now the type of the request corresponds to the operation:

  • POST - after editing data of the component;
  • PUT - after adding new data into the component;
  • DELETE - after deleting data.

Thanks for the Info, but i have changed to WEBIX, works great…