DHTMLX Docs & Samples Explorer

Index
dhtmlxgrid

## Validation

Data validation can be done in few different ways

- Through events of grid;
- Through “validation extension”;
- Through client|server side validators of DataProcessor.

### Validation by Events

Grid provides two events, which can be used for validation purposes - onCellChanged and onEditCell

    grid.attachEvent("onCellChanged",function(id,index,value){
         if (index == SOME && !some_check(value))
              grid.cells(id,index).setCValue("invalid");
    })

or

    grid.attachEvent("onEditCell",function(stage,id,index,new_value,old_value){
         if (stage == 2 && index == SOME && !some_check(new_value))
              return false; //deny edit operation
    })

### Validation extension

Starting from dhtmlxGrid 2.2 there is a standalone validation extension. It uses the same approach as described above solution, but hides all details about which events and how need to be used, providing abstract validation interface.

To use extension you need to include next js file

         <script src="codebase/ext/dhtmlgrid_validation.js">

Validation rules created through extension can work in two modes:

- Basic - data check occurs when edit operation finished;
- Live - data check executed in same time while user typing new value.

Rules can be defined per column, or fore some specific cells only.

Extension provides - predefined validation rules and ability to create custom rules.

In addition to default usage scenario it possible to force data checking at any time by script command, integrate them with dataprocessor or use additional events to customize them even more.

### Validation through DataProcessor

Dataprocessor has its own way to attach validation. Its validation check will run exactly before data sending to the server and block data sending if data was invalid.