On Cell Change
- Last UpdatedApr 20, 2022
- 1 minute read
Use scripts for the On Cell Change event of a Grid widget to validate changes to a cell value.
This event gets the value for the modifiedValue and oldValue properties of the Grid widget. For more information on validating changes, see Validate Data.
Example
If you want to verify the modified value of a column, you can have a script like in the following example. This verifies that the modified value of the description column is "desc".
When you modify a cell value and remove focus from the cell, the On Cell Change event is triggered.
var validate = {};
var validate1 = function(validate)
{
var modified = (JSON.parse(event.modifiedvalue));
//To get a modified value of a column name (example: description)
var description = (modified).description;
// To check a column value (example: description column has a value of a sample string value "desc")
if (description=="desc")
{
validate.result = true;
}
else
{
validate.result = false;
}
validate.Functionname = "Validate";
return validate;
};
control.findByXmlNode("Widget1").widgetProperties.notify=JSON.stringify(validate1(validate));
To get the previous row value of a Grid widget, you can use the following script:
var oldvalue = (JSON.parse(event.oldvalue));
// To get previous value of a column name: abbreviation
var oldabb = (oldvalue).abbreviation;
// To get previous value of a column name: description
var olddes = (oldvalue).description;