OS3Grid Example 4 - Editable Grid

By Fabio Rotondo - fsoft (@) sourceforge ( dot ) net

Main Page
Simple Grid
Sortable Grid
Sortable Grid
Editable Grid
Custom Callbacks
Rows Selection
Column Resize
Column Renderers
Setting and Using Styles
Using OS3Grid to edit a dataset
Advanced Cell Value Manipulation
Support OS3Grid
Let's see now how to let the user edit our grid.
First of all, we have to set the columns that we want the user to be able to edit, this is done by the following commands:
				g.set_col_editable ( 1, "txt" );
				g.set_col_editable ( 2, "txt" );
				g.set_col_editable ( 3, "txt" );
		
Since the last field should contain an e-mail, we can force the user to insert valid chars by filtering his/her typing against the given string and by adding a field validator:
				g.set_col_valid_chars ( 3, "abcdefghijklmnopqrstuvwxyz@.-0123456789_" );
				g.set_col_validation ( 3, check_email );
		
The check_email is a form validation function defined inside form_validators.js. This file contains many more pre made validators, take a look at it and, if you are using it, do not forget to add the JavaScript file in your document with the following code:
			<script src="form_validators.js" type="text/javascript"></script>
		
If we want the grid rows to be automatically resorted when the user changes grid contents, simply set this flag to true:
				g.sort_on_edit = true;
		
That's all! The final result is shown below.