Posted 22 March 2021, 9:53 pm EST
Hi Shaily,
It is by design, actually, we followed the Excel DataValidation policy.
- When copy a cell from one to another, not only cell’s value but also cell’s options: formula, style, data validator… will also paste on the target cell. hence, customer need to set clipBoardOptions to only paste value to the cell, otherwise, the target cell’s data validator will be overwritten by the source cell.
It is the same with Excel.
- When paste value to the cell which have data validator, it will not execute the data validation, because paste is a range behavior, if some of the cell in the range are valid but some are not, the data validation could not handle this case.hence, the same with Excel, in that case, we don’t fire validationError event. but, the value will be validated internally and show a red circle if it is incorrect.
For #2 You could use ClipBoardPasted Event or DragFillBlockCompleted and Varify the range validation. Please refer to the following code snippet and attached sample that demonstrate the same.
spread.options.defaultDragFillType =
GC.Spread.Sheets.Fill.AutoFillType.fillWithoutFormatting;
sheet.options.clipBoardOptions =
GC.Spread.Sheets.ClipboardPasteOptions.values;
sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, (e, args) => {
isValidrange(args.sheet, args.cellRange);
});
sheet.bind(GC.Spread.Sheets.Events.DragFillBlockCompleted, (e, args) => {
isValidrange(args.sheet, args.fillRange);
});
}
function isValidrange(sheet, range) {
sheet.suspendPaint();
for (let row = range.row; row < range.row + range.rowCount; row++) {
for (let col = range.col; col < range.col + range.colCount; col++) {
let validator = sheet.getDataValidator(row, col);
let NewValue = sheet.getValue(row, col);
if (validator && validator.getValidList().indexOf(NewValue) === -1)
//set the Value if the pasted value is not inside the valid List
// you may also alert the user here
console.log("CellValue is Invalid reseting the Cell");
sheet.setValue(row, col, validator.getValidList()[0]);
}
}
sheet.resumePaint();
}
sample: https://codesandbox.io/s/spread-js-starter-forked-992hy
Regards
Avinash