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
28253Employee name...employee@email.com2011-01-010.00
28252tetoteto@email.com2011-01-010.00
28251mostafa ahmedmostafaahmll@yahoo.com2011-01-010.00
28250mostaaf ahmedmostafaahmed@gmail.com2011-01-010.00
28249Employee name...employee@email.com2011-01-010.00
28248Employee name...employee@email.com2011-01-010.00
28247Employee name...employee@email.com2011-01-010.00
28246Employee name...employee@email.com2011-01-010.00
28245Employee name...employee@email.com2011-01-010.00
28244Employee name...employee@email.com2011-01-010.00
28243Employee name...employee@email.com2011-01-010.00
28242Employee name...employee@email.com2011-01-010.00
28241Employee name...employee@email.com2011-01-010.00
28240Employee name...132@email.com2011-01-010.00
28239asdasdadasdasd@email.com2011-01-010.00
28235Employee name...employee@email.com2011-01-010.00
28234Employee name...employee@email.com2011-01-010.00
28233Employee name...employee@email.com2011-01-010.00
28232zxczczxcxcemployee@email.com2011-01-010.00
28231Employee name...employee@email.com2011-01-010.00
28230Employee name...employee@email.com2011-01-010.00
28229Robertde@niro.com2011-01-010.00
28228Employee name...employee@email.com2011-01-010.00
28227sdsemployee@email.com2011-01-010.00
28225Employee name...employee@email.com2011-01-010.00
28224Toto Cutognototoo@yahoo.com2000-05-040.00
28223Employee name...employee@email.com2011-01-010.00
28222Employee name...employee@email.com2011-01-010.00
28221fgjhemployee@email.com2011-01-010.00
28220Employee name...employee@email.com2011-01-010.00
28219Employee name...employee@email.com2011-01-010.00
28218Employee name...employee@email.com2011-01-010.00
28217Employee name...employee@email.com2011-01-010.00
28216Employee name...employee@email.com2011-01-010.00
28215Employee name...employee@email.com2011-01-010.00
28214Employee name...employee@email.com2011-01-010.00
28213Employee name...employee@email.com2011-01-010.00
28212Employee name...employee@email.com2011-01-010.00
28211Employee name...employee@email.com2011-01-010.00
28210Employee name...123@email.com2011-01-012.00
28209Employee name...employee@email.com2011-01-010.00
28208Employee name...employee@email.com2011-01-010.00
28207hoaraumon@gmail.com2011-01-010.00
28206Employee name...employee@email.com2011-01-010.00
28205Employee name...employee@email.com2011-01-010.00
28204Employee name...employee@email.com2011-01-010.00
28203Employee name...employee@email.com2011-01-010.00
28201Employee name...mon@gmail.com2011-01-010.00
28200Employee name...employee@email.com2011-01-010.00
28199Employee name...employee@email.com2011-01-010.00
28198Employee name...employee@email.com2011-01-010.00
28197Employee name...employee@email.com2011-01-010.00
28196asfasfa sdfasdfasfemployee@email.com2011-01-010.00
28195sdssdemployee@email.com2011-01-010.00
28194Employee name...ssdsds@email.com2011-01-010.00
28193Employee name...employee@email.com2011-01-010.00
28191Employee name...employee@email.com2011-01-010.00
28190Employee name...employee@email.com2011-01-010.00
28189Employee name...employee@email.com2011-01-010.00
28188Employee name...employee@email.com2011-01-010.00
28187Employee name...employee@email.com2011-01-010.00
28186Employee name...employee@email.com2011-01-010.00
28185Employee name...employee@email.com2011-01-010.00
28184Employee name...employee@email.com2011-01-010.00
28183Employee name...employee@email.com2011-01-010.00
28182Employee name...employee@email.com2011-01-010.00
28181Employee name...employee@email.com2011-01-010.00
28180Employee name...employee@email.com2011-01-010.00
28179Employee name...employee@email.com2011-01-010.00
28178Employee name...employee@email.com2011-01-010.00
28177Employee name...employee@email.com2011-01-010.00
28176Employee name...employee@email.com2011-01-010.00
28175Employee name...employee@email.com2011-01-010.00
28174Employee name...employee@email.com2011-01-010.00
28173Employee name...employee@email.com2011-01-010.00
28172Employee name...employee@email.com2011-01-010.00
28171Employee name...employee@email.com2011-01-010.00
28170Employee name...employee@email.com2011-01-010.00
28169Employee name...employee@email.com2011-01-010.00
28168Employee name...employee@email.com2011-01-010.00
28167Employee name...employee@email.com2011-01-010.00
28166Employee name...employee@email.com2011-01-010.00
28165Employee name...employee@email.com2011-01-010.00
28164Employee name...employee@email.com2011-01-010.00
28163Employee name...employee@email.com2011-01-010.00
28162Employee name...employee@email.com2011-01-010.00
28161Employee name...employee@email.com2011-01-010.00
28152Employee name...employee@email.com2011-01-010.00
28151Employee name...employee@email.com2011-01-010.00
28148Employee name...employee@email.com2011-01-010.00
28146kkemployee@email.com2011-01-010.00
28144edit3employee@email.com2011-01-010.00
28142poipopemployee@email.com2011-01-010.00
28141homeemployee@email.com2011-01-010.00
28140Employee name...employee@email.com2011-01-010.00
28138Employee name...employee@email.com2011-01-012.00
28135testtest@gmail.com2017-09-1020.00
28134Employee name...employee@email.com2011-01-010.00
28133Employee name...employee@email.com2011-01-010.00
28132testemployee@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!