Editable Grid

To make a grid editable you need to enable the editable property and configure the ezEditTable configuration object (ezEditTable_config). This demo shows how to :

Please note that is a live demo and your tests will be recorded in a database!

Id Name Email Start Date Salary Active
30098Employee name...employee@email.com2011-01-010.00
30097Employee name...employee@email.com2011-01-010.00
30096Employee name...employee@email.com2011-01-010.00
30095Employee name...employee@email.com2011-01-010.00
30094Employee name...employee@email.com2011-01-010.00
30093Employee name...employee@email.com2011-01-010.00
30092iipipipipipipemployee@email.com2011-01-010.00
30089Boboemployee@email.com2011-01-010.00
30088Employee name...employee@email.com2011-01-010.00
30087Employee name...employee@email.com2011-01-010.00
30086Employee name...employee@email.com2011-01-010.00
30085Employee name...employee@email.com2011-01-010.00
30084Employee name...employee@email.com2011-01-010.00
30083Employee name...employee@email.com2011-01-010.00
30082Employee name...employee@email.com2011-01-010.00
30081Employee name...employee@email.com2011-01-010.00
30080Employee name...employee@email.com2011-01-010.00
30079Employee name...employee@email.come2011-01-0110.00
30078Employee name...employee@email.com2011-01-010.00
30077Employee name...aaaaaa@ercan.com.tr2008-04-150.00
30076Employee name...employee@email.com2011-01-010.00
30075Employee name...employee@gmail.com1996-08-0125.09
30074Employee name...employee@email.com2011-01-010.00
30073Employee name...employee@email.com2011-01-010.00
30072Employee name...employee@email.com2011-01-010.00
30071Employee name...employee@email.com2011-01-010.00
30070Employee name...employee@email.com2011-01-010.00
30069Employee name...employee@email.com2011-01-010.00
30068Employee name...employee@email.com2011-01-010.00
30067Employee name...employee@email.com2011-01-010.00
30066Employee name...employee@email.com2011-01-010.00
30065Employee name...employee@email.com2011-01-010.00
30064Employee name...employee@email.com2011-01-010.00
30063Employee name...employee@email.com2011-01-010.00
30062Employee name...employee@email.com2011-01-010.00
30061Employee name...employee@email.com2011-01-010.00
30060Employee name...employee@email.com2011-01-010.00
30059Employee name...employee@email.com2011-01-010.00
30058Employee name...employee@email.com2011-01-010.00
30057Employee name...employee@email.com2011-01-010.00
30056Employee name...employhhee@email.com2011-01-010.00
30055Employee name...employee@email.com2011-01-010.00
30054Employee name...employee@email.com2011-01-010.00
30053Employee name...employee@email.com2011-01-010.00
30052Employee name...employee@email.com2011-01-010.00
30051Employee name...employee@email.com2011-01-010.00
30050Employee name...employee@email.com2011-01-010.00
30049Employee name...employee@email.com2011-01-010.00
30048Employee name...employee@email.com2011-01-010.00
30047Employee name...employee@email.com2011-01-010.00
30046Employee name...employee@email.com2011-01-010.00
30045Employee name...employee@email.com2011-01-010.00
30044Employee name...employee@email.com2011-01-010.00
30043Employee name...employee@email.com2011-01-010.00
30042Employee name...employee@email.com2011-01-010.00
30039Employee name...employee@email.com2011-01-010.00
30038Employee name...employee@email.com2011-01-010.00
30037Employee name...employee@email.com2011-01-010.00
30036Employee name...employee@email.com2011-01-010.00
30035Employee name...employee@email.com2011-01-010.00
30034Employee name...employee@email.com2011-01-010.00
30033Employee name...employee@email.com2011-01-010.00
30032Employee name...employee@email.com2011-01-010.00
30031Employee name...employee@email.com2011-01-010.00
30030Employee name...employee@email.com2011-01-010.00
30029Employee name...employee@email.com2011-01-010.00
30028Employee name...employee@email.com2011-01-010.00
30027Employee name...employee@email.com2011-01-010.00
30026Employee name...employee@email.com2011-01-010.00
30025Employee name...employee@email.com2011-01-010.00
30024Employee name...employee@email.com2011-01-010.00
30023Nur Dheereemployee@email.com2011-01-010.00
30022Employee name...employee@email.com2011-01-010.00
30021Employee name...employee@email.com2011-01-010.00
30020Employee name...employee@email.com2011-01-010.00
30019Employee name...employee@email.com2011-01-010.00
30018Employee name...employee@email.com2011-01-010.00
30017Employee name...employee@email.com2011-01-010.00
30016Employee name...employee@email.com2011-01-010.00
30015Employee name...employee@email.com2011-01-010.00
30014Employee name...employee@email.com2011-01-010.00
30013gumbyemployee@email.com0000-00-00600.00
30012pokeyemployee@email.com2011-01-01300.00
30011steveemployee@email.com2011-01-010.00
30010bettyemployee@email.com2011-01-010.00
30009wilmaemployee@email.com2011-01-010.00
30008bubbabubba@bubba.com2011-01-010.00
30007The Dudeemployee@email.com2011-01-010.00
30006Employee name...sdfsdf@ioi.edu2011-01-010.00
30005gretgtrgeemployee@email.com2011-01-010.00
30004rtgrtgemployee@email.com2011-01-010.00
30003rtgretgemployee@email.com2011-01-010.00
30002Employee name...employee@email.com2011-01-010.00
30001Employee name...employee@email.com2011-01-010.00
30000Employee name...employee@email.com2011-01-010.00
29999Employee name...employee@email.com2011-01-010.00
29998fdsvfdsvemployee@email.com2011-01-010.00
29997efrdfgbdfbemployee@email.com2011-01-010.00
29996Employee name...employee@email.com2011-01-010.00
29995dweemployee@email.com2011-01-010.00
		//Validation functions
		function et_ValidateEmail(email){
		   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		   return reg.test(email);
		}

		function et_IsNumber(val){
			var isNumber = /^\d+\.\d{2}$/;
			return isNumber.test(val);
		}

		var tfConfig = {
			btn_reset: true,
			alternate_rows: true,
			col_0: 'none', col_5: 'none',
			rows_counter: true,
			col_width:['50px', '280px', '220px', '100px', '100px', '70px'],
			col_date_type: [null,null,null,'ymd',null,null],
			sort_config: { sort_types: ['number','string','string','ymd','number','none'] },
			grid_layout: true, grid_width: '860px', grid_height: '300px',

			selectable: true,
			editable: true,
			ezEditTable_config: {
				loadStylesheet: true,
				default_selection: 'both',
				editor_model: 'cell',
				form_submit_interval: 999,
				cell_editors:[
					{ type: 'none' },
					{ type: 'input', attributes:[['title', 'First name and last name']] },
					{ type: 'input', attributes:[['title', 'email address']] },
					{ type: 'custom', target: 'dateEditor' },
					{ type: 'input', attributes:[['maxLength', 10], ['title', '10 digits max.\n numbers with 2 decimal places only']], css:'alignRight' },
					{ type: 'boolean' }
				],
				actions:{
					'update': {
						uri: 'php/employeeUpdate.php', submit_method: 'form', form_method: 'POST',
						param_names: ['id','name','email','startdate','salary','active']
					},
					'insert': {
						uri: 'php/employeeInsert.php', submit_method: 'form', form_method: 'POST',
						param_names: ['id','name','email','startdate','salary','active'],
						default_record: ['', 'Employee name...', 'employee@email.com', '2011-01-01','0.00', '']
					},
					'delete': {
						uri: 'php/script.deleteEmployee.php', submit_method: 'script', bulk_delete: false,
						param_names: ['id']
					}
				},

				//Data validation delegate, the script does not provide data validation tools
				validate_modified_value: function(o, colIndex, oldVal, newVal, cell, editor){
					if(colIndex==2 && oldVal != newVal){
						if(!et_ValidateEmail(newVal)){
							alert('Please insert a valid email!');
							return false;
						} else return true;
					}
					else if(colIndex == 4 && oldVal != newVal){
						if(!et_IsNumber(newVal)){
							alert('Please insert a valid number with 2 decimal places!');
							return false;
						} else return true;
					}
					else return true;
				},

				//Custom editor functions
				open_custom_editor: function(o, cell, editor){
					cell.appendChild(editor);
					editor.style.display = '';
				},
				close_custom_editor: function(o, cell, editor){
					editor.style.display = 'none';
					document.body.appendChild(editor);
					var d = o.Get('daySlc'), m = o.Get('monthSlc'), y = o.Get('yearSlc');
					d.value = '';
					m.value = '';
					y.value = '';
				},
				get_custom_editor_value: function(o, editor, colIndex){
					var strDate;
					var d = o.Get('daySlc'), m = o.Get('monthSlc'), y = o.Get('yearSlc');
					strDate = y.value+'-'+m.value+'-'+d.value;
					return strDate;
				},
				set_custom_editor_value: function(o, editor, colIndex, val){
					o.config.SetDateEditorValue(o, val, 'YMD');
				},


				//Custom date editor function, does not belong to ezEditTable script
				SetDateEditorValue: function(o, val, dateType){
					var date = tf_FormatDate(val, dateType);
					var d = o.Get('daySlc'), m = o.Get('monthSlc'), y = o.Get('yearSlc');
					var day = date.getDate(), month = date.getMonth()+1, year = date.getFullYear();
					d.value = day.toString().length==1 ? '0'+day.toString() : day;
					m.value = month.toString().length==1 ? '0'+month.toString() : month;
					y.value = year;
				}
			}

		};
		

Below the server-side PHP codes for DB operations used in this demo:

Insert:
<?php
if(isset($_POST["id"]) && isset($_POST["name"]) && isset($_POST["email"])){
	$id = $_POST["id"];
	$name = echappement(utf8_urldecode($_POST["name"]));
	$email = echappement(utf8_urldecode($_POST["email"]));
	$startdate = $_POST["startdate"];
	$salary = $_POST["salary"];
	$active = $_POST["active"];
	$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
	if($active == 'true') $active = 1;
	else $active = 0;

	connect_db();
	$query = "INSERT INTO ".TBL_DEMO_EMPLOYEE." ".
				" VALUES('0','$name','$email','$startdate','$salary',".
				"'$ip', null, null, NOW(), null, null, $active, 0)";
	mysql_query($query);
	close_db();
}
?>
		
Update:
<?php
if(isset($_POST["id"]) && isset($_POST["name"]) && isset($_POST["email"])){
	$id = $_POST["id"];
	$name = echappement(utf8_urldecode($_POST["name"]));
	$email = echappement(utf8_urldecode($_POST["email"]));
	$startdate = $_POST["startdate"];
	$salary = $_POST["salary"];
	$active = $_POST["active"];
	$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
	if($active == 'true') $active = 1;
	else $active = 0;

	connect_db();
	$query = "UPDATE ".TBL_DEMO_EMPLOYEE." SET ".
				"NAME='$name',EMAIL='$email',STARTDATE='$startdate',SALARY='$salary'".
				",MODIP='$ip',MODDATE=NOW(),ACTIVE=$active ".
				"WHERE ID='$id'";
	mysql_query($query);
	close_db();
}
?>
		
Delete:

Records deleting is performed in this case via <script> tag inclusion method, ... submit_method: 'script', ... (GET http request), therefore do not forget to specify the javascript content-type in your server-side code:

<?php
header("content-type: application/x-javascript");
if(isset($_GET["id"])){
	$id = $_GET["id"];
	$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
	connect_db();
	$query = "UPDATE ".TBL_DEMO_EMPLOYEE." SET ".
				"DELIP='$ip',DELDATE=NOW(),DELETED=1 ".
				"WHERE ID='$id'";
	mysql_query($query);
	close_db();
}
?>
		

E.n.j.o.y.  ads-free content!