Here are some common scenarios that may sound familiar to you:
Did you know that you can do all of these in SpreadJS? SpreadJS provides data validation similar to Excel, to control the type of data or the value that users enter into a cell. There are many types of built in -data validators inside SpreadJS that you mayuse to validate data entry in the cell. First of all you need to create a data validator by static methods of DefaultDataValidator class, and set the data validator by the dataValidator method of the Cell class to the cell which need data validation. DefaultDataValidator class provide 6 type of data validator, easy to create different criteria validator for your variety requirement. They are:
Here is a sample, create a number validator to check entered value should be between 5 and 10.
var dv = $.wijmo.wijspread.DefaultDataValidator.createNumberValidator($.wijmo.wijspread.ComparisonOperator.Between, 5, 10, true);
dv.errorMessage = "value should be number and between 5 and 10";
sheet.getCell(1, 1).dataValidator(dv);
The second, add code in ValidationError event to process result of validation. This event will be fired when a cell is ending the editing if the entered value is invalid. In event arguments, you can get sheet object which the cell belong to, row index and column index of the cell, validator of the cell, and validationResult this is a flag indicate how to process the invalid value, type of this flag is DataValidationResult, it has three options:
spread.bind($.wijmo.wijspread.Events.ValidationError, function (event, data) {
var dv = data.validator;
if (dv) {
alert(dv.errorMessage);
if(data.row==0 && data.col==1) {
// finish editing, and restor the original value
data.validationResult=$.wijmo.wijspread.DataValidationResult.Discard;
} else if(data.row==1 && data.col==1) {
// keep editing until enter a valid value
data.validationResult=$.wijmo.wijspread.DataValidationResult.Retry;
}
}
});
You can try the sample page, to learn more about getting started with SpreadJS in a web page, please read Quick Start Guide to Using SpreadJS. For more information about how to use SpreadJS, includes its data model and API, please read our online documentation or try online demos.