As noted, Slickgrid validation is limited by default to the validate editor function, which checks for any validator available validator passing only the value as a parameter. To provide additional contextual information, a special editor or, more specifically, a special validation function is required.
this.validate = function() { if (args.column.validator) { args.newValue = $input.val() var validationResults = args.column.validator(args); if (!validationResults.valid) { return validationResults; } } return { valid: true, msg: null }; };
Each column should then have a validator within which the default value will be checked either with a new value coming from the editor or with an existing value, as well as with any other necessary aspects of the check.
var Validator = function(args) {
To validate the entire grid, enter a validation method that iterates through each row, looking at each column for the validator. Based on the results of the check, a relational mapping rowIndex -> collection of failures , which should be passed to the native onValidationError event. This allows the subscription to process user notifications of errors. In addition, the results of the check can be used to erase errors in the provision of certain metadata to the grid.
var validateColumns = function(args){ var failures=[]; for (c in columns) { var column = columns[c] if (column.validator) { if(!column.validator({row: args.row, item: args.item, column: column}).valid){ failures.push({columnIndex: c, column: column, rowIndex: args.row, item: args.item}) } } } return failures; } grid.validate = function() { var rowFailures = {} for (r in data) {
source share