Skip to content

Instantly share code, notes, and snippets.

@Narshe1412
Created June 6, 2019 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Narshe1412/77afbe463eacf37d422a611268425e5c to your computer and use it in GitHub Desktop.
Save Narshe1412/77afbe463eacf37d422a611268425e5c to your computer and use it in GitHub Desktop.
SpreadJS: Create List Validator from Array including empty option
export const getListValidatorFromArray = (spread: GC.Spread.Sheets.Workbook, data: any[]) => {
// saving validation list values in a hidden sheet
spread.addSheet(spread.getSheetCount());
const sheet = spread.getSheet(spread.getSheetCount() - 1);
sheet.visible(false);
for (let i = 0; i < data.length; i++) {
sheet.setValue(i, 0, data[i]);
}
// create validator based on the values
const dv = GC.Spread.Sheets.DataValidation.createFormulaListValidator(
'=' + sheet.name() + '!$A$1:' + sheet.name() + '!$A$' + data.length
);
return dv;
};
@Narshe1412
Copy link
Author

Full story: https://stackoverflow.com/q/56040022/5866637

Note: This creates an extra sheet for each validator you create. Makes sure you reuse them as much as possible (i.e. assigning it to a variable when it's created, and reusing the variable for other columns/rows that use the same one).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment