Data validation

The following example demonstrates cell validation. Use the validatormethod to easily validate synchronous or asynchronous changes to a cell. If you need more control, beforeValidateand afterValidateplugin hooks are available. In the below example, email_validator_fnis an async validator that resolves after 1000 ms.

 
ID
First name
Last name
IP
E-mail
1
1JoeFabiano0.0.0.1Joe.Fabiano@ex.com
2
2FredWecler0.0.0.1Fred.Wecler@ex.com
3
3SteveWilson0.0.0.1Steve.Wilson@ex.com
4
4MariaFernandez0.0.0.1M.Fernandez@ex.com
5
5PierreBarbault0.0.0.1Pierre.Barbault@ex.com
6
6NancyMoore0.0.0.1Nancy.Moore@ex.com
7
7BarbaraMacDonald0.0.0.1B.MacDonald@ex.com
8
8WilmaWilliams0.0.0.1Wilma.Williams@ex.com
9
9SashaSilver0.0.0.1Sasha.Silver@ex.com
10
10DonPérignon0.0.0.1Don.Pérignon@ex.com
11
11AaronKinley0.0.0.1Aaron.Kinley@ex.com
 
ID
First name
Last name
IP
E-mail
 
1
2
3
4
5
6
7
8
9
10
11
 

Edit the above grid to see callback:

// Validation callback
JavaScript
Drag down

Drag down example. Notice the little square (fillhandle) in the corner of the selected cell. You can drag it (drag-down) to repeat the values from the cell. Double click the fill handle in cell B8(value "47382") to fill the selection down to the last value in neighbouring column, just like it would in LibreOffice or Google Docs.

 
A
B
C
D
E
F
G
1
KiaNissanToyotaHondaMazdaFord
2
2008458331229312894788594772943054
3
2009342344890249950588235788289954
4
2010859439044938882349284539723487
5
2011449509009289932899458900358943
6
2012234868339447729239459900148995
7
2013903925828248852177893298423498
8
2014473828845790029588754539848995
9
2015
10
2016
11
2017
 
A
B
C
D
E
F
G
 
1
2
3
4
5
6
7
8
9
10
11
 
Merge cells

The following example demonstrates an ability to merge table cells. To enable the merge cells feature, set the mergeCellsoption to be trueor an array. To initialize Handsontable with predefined merged cells, provide merged cells details in form of an array: mergeCells: [{row: 1, col: 1, rowspan: 2, colspan: 2}]. Context menu provides an option to merge/unmerge the cells.

 
A
B
C
D
E
F
G
H
I
J
1
A1B1C1D1E1F1G1H1I1J1
2
A2B2C2D2E2F2G2H2I2J2
3
A3B3C3D3E3F3G3H3I3J3
4
A4B4C4D4E4F4G4H4I4J4
5
A5B5C5D5E5F5G5H5I5J5
6
A6B6C6D6E6F6G6H6I6J6
7
A7B7C7D7E7F7G7H7I7J7
8
A8B8C8D8E8F8G8H8I8J8
9
A9B9C9D9E9F9G9H9I9J9
10
A10B10C10D10E10F10G10H10I10J10
11
A11B11C11D11E11F11G11H11I11J11
12
A12B12C12D12E12F12G12H12I12J12
 
A
B
C
D
E
F
G
H
I
J
 
1
2
3
4
5
6
7
8
9
10
11
12
 
Alignment

To initialize Handsontable with predefined horizontal and vertical alignment, provide className cells details in form of a grid, columns or cell setting. Available classNames: Horizontal- htLeft, htCenter, htRight, htJustify; Vertical- htTop, htMiddle, htBottom. Context menu also includes alignment option for both horizontal and vertical orientations.

 
A
B
C
D
E
F
G
H
I
J
1
A1B1C1D1E1F1G1H1I1J1
2
A2B2E2F2G2H2I2J2
3
A3E3F3G3H3I3J3
4
A4E4G4H4I4J4
5
A5B5C5D5G5H5I5J5
6
A6B6C6D6E6F6G6H6I6J6
7
A7B7C7D7E7F7G7H7I7J7
8
A8B8C8D8E8F8G8H8I8J8
9
A9B9C9D9E9F9G9H9I9J9
10
A10B10C10D10E10F10G10H10I10J10
11
A11B11C11D11E11F11G11H11I11J11
12
A12B12C12D12E12F12G12H12I12J12
 
A
B
C
D
E
F
G
H
I
J
 
1
2
3
4
5
6
7
8
9
10
11
12
 
Read only

The following example demonstrates how to configure columns or cells to be read only. Here cells that contain the word "Nissan"are read only. It forces all cells to be rendered by myReadonlyRenderer, which will decide whether a cell is really read only by checking its readOnlyproperty. To make a full column read only, declare it in the columnssetting. You can also define a special renderer function that will dim the read-only values.

Car
Year
Chassis color
Bumper color
Toyota2008whitewhite
Chevrolet2010greyblack
Lexus2006redblack
Nissan2013purplepurple
Volvo2012redred
Nissan2011blackgrey
Nissan2012blackblack
Nissan2013blueblue
Chrysler2014yellowblack
Volvo2015whitegrey
Car
Year
Chassis color
Bumper color
Disable cell editing

The following example demonstrates how to configure columns or cells to be not editable. Here the table with non-editable cells containing the word “Nissan”. This property of the cell is optional and can be easily set in the configuration of Handsontable. To make a full column non-editable, declare it in the columnssetting. You can also define a special renderer function that will dim the editor value.

Car
Year
Chassis color
Bumper color
Toyota2008whitewhite
Chevrolet2010greyblack
Lexus2006redblack
Nissan2013purplepurple
Volvo2012redred
Nissan2011blackgrey
Nissan2012blackblack
Nissan2013blueblue
Chrysler2014yellowblack
Volvo2015whitegrey
Car
Year
Chassis color
Bumper color