Best way to make complex validation

Tags: #<Tag:0x00007f51c6b5d398> #<Tag:0x00007f51c6b5d230>

Hello devs :wink: I need to implement validation for a table that consists of two columns. Rules 1 and 2 should work independently for each column, while Rule 3 should consider values from both columns simultaneously.

As I understand it, using a validator for individual columns won’t work because the validation is too complex. Additionally, if at least one case is invalid, the entire column will be highlighted.

Can you guide me in the right direction on how to implement such validation? Also, how can I make it trigger immediately when table data is loaded onto the server? From what I understand, the validator only triggers when values in the table are changed, not on initialization. Additionally, I need to implement highlighting of the table header in red if at least one validation check fails.

Validation Rules

  1. Name: Values should not be empty except for the last ones in the list. Intermediate values must not be zero.

    Rule: !(x(i-1) != " " & x(i+1) != " " & x(i) == " ")

    Comment: i is the row number of the cell being checked in column x.

  2. Name: The absolute difference between two consecutive values in the same column must not exceed the allowable limit or be zero.

    Rule: abs(x(i-1) - x(i)) <= n & abs(x(i+1) - x(i)) <= n & x(i-1) - x(i) != 0 & x(i+1) - x(i) != 0

    Comment: i is the row number of the cell being checked in column x.

  3. Name: Values in both columns must be either monotonically increasing or decreasing.

    Rule: (x(i-1) > x(i) & x(i) > x(i+1) & y(i-1) > y(i) & y(i) > y(i+1)) || (x(i-1) < x(i) & x(i) < x(i+1) & y(i-1) < y(i) & y(i) < y(i+1))

    Comment: i is the row number of the cell being checked in either column x or column y.

image

Hi @mr.fursy

Regarding the validation, you can trigger it at initizalization programmatically with the validateCell or validateCells method: https://handsontable.com/docs/javascript-data-grid/api/core/#validatecells

If you need to modify the column headers styling you can use this hook: https://handsontable.com/docs/javascript-data-grid/api/hooks/#aftergetcolheader