Skip to main content

setValidation()

Description

Sets validation for cells via adding drop-down lists into the cells

The method can also remove data validation from a cell(s).

Usage

setValidation(
cell: string,
options: string | string[]
): void;

Parameters

  • cell - (required) the id(s) of a cell(s) or a range of cells
  • options - (required) either a string with a range of cells ("C1: C3") or an array of string values

Example

const spreadsheet = new dhx.Spreadsheet("spreadsheet", {
// config parameters
});

spreadsheet.parse(dataset);

// sets validation and creates a drop-down list with 3 items to choose for B10 cell
spreadsheet.setValidation("B10", ["Apple", "Mango", "Avocado"]);

Details

If you need to remove validation from a cell(s), instead of the list of options, pass null / 0 / false / undefined as a second parameter to the method:

spreadsheet.setValidation("B15");

//or
spreadsheet.setValidation("B15", null);

//or
spreadsheet.setValidation("B15", false);

Change log: Added in v4.3

Related articles: Validating cells