Hi,
We have a grid, which has 2 columns, "Name" "Age". if user enters the Age as negative, then it will convert to positive all the time. eg, -32 to 32
In the grid event we have "event save" to trigger it to make positive value all the time by using Math.abs(Age). We can see the datasource has updated value, also after refresh() everything look good inside the "save" method, once it is out of the "save", the value gets rollback to the user's input as = -32 again. it seems like kendo has methods which puts it back. How can I get round it?
This happens only when we try to modify user's input in the same field. There is no problem if user change their name column, and we code to change age to positive
I set a breakpoint after "$("#NameAgeGrid").data("kendoGrid").refresh();" in the following code, and everything looks good. once I continue, it went to kendo's code "set: function (field, value) " and "set: function (field, value, initiator)" and then the value gets put back
thanks!
in cshtml:
.Events(e => e.Save("NameAgeGrid_onSave"))
in JS:
if ("Age" in e.values && e.values.Age != "") {
e.model.set("Age", Math.abs(e.values.Age));
e.model.Age = Math.abs(e.values.Age);
var datarow = $("#NameAgeGrid").data("kendoGrid").dataSource.getByUid(e.model.uid);
datarow.Age = Math.abs(e.values.Age);
$("#Age").val(Math.abs(e.values.Age)).change();
$("#NameAgeGrid").data("kendoGrid").refresh();
}