Demos

AJAX

This demo shows how to

Please note that the AJAX requests are performed with jQuery, therefore it is has to be imported in the document. If jQuery is not found, ezEditTable will fallback automatically to a plain form submission method.

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

Id Name Email Start Date Salary Active
52964the highest Date is in 2019...employee@email.com2019-12-010.00
52961asdfsdafemployee@email.com2011-01-0110.10
52960dokter darkdokter_dark@email.com2011-01-010.00
52958testtest@email.com2011-01-010.00
52957dfddsfgemployee@email.com2011-01-010.00
52956nombreemployee@email.com2011-01-010.00
52955Employee name...employee@email.com2011-01-060.00
52952Employee name...employee@email.com2011-01-010.00
52951Employee name...employee@email.com2011-01-010.00
52950testemployee@email.com2011-04-020.00
52940Employee name...employee@email.com2011-01-010.00
52939Employee name...employee@email.com2011-01-010.00
52938erg4g24tgh42temployee@email.com2011-01-010.00
52937ze name...employee@email.com2011-01-010.00
52936Employee name...employee@email.com2011-03-120.00
52935Employee name...employee@email.com2011-01-010.00
52934Employee name...employee@email.com2011-01-010.00
52931siano na sniadanie dla koziolkadfskoziolek@email.com0000-00-000.00
52922tstingemployee@email.com2011-01-050.00
52921Test Me NOWemployee1@email.com2011-01-010.00
52905oöoiöoiöoiöioöoiöemployee@email.com2011-01-010.00
52904Employee name...employee@email.com2011-01-010.00
52901rrrrremployee@email.com2011-01-010.00
52900Employee name...employee@email.com2011-01-010.00
52899Employee name...employee@email.com2011-01-010.00
52898Employee name...employee@email.com2011-01-010.00
52897Employee name...employee@email.com2011-01-010.00
52895i7i7l78l789employee@email.com2011-01-010.00
52894Employee name...employee@email.com2011-01-010.00
52893Employee name...employee@email.com2011-01-010.00
52892Employee name...employee@email.com2011-01-010.00
52891Employee name...employee@email.com2011-01-010.00
52888employee@email.com2011-01-010.00
52887Employee name...employee@email.com2011-01-010.00
52886Employee name...employee@email.com2011-01-010.00
52885Employee name...employee@email.com2011-01-010.00
52884Employee name...employee@email.com2011-01-010.00
52883Employee name...employee@email.com2011-01-010.00
52882Employee name...employee@email.com2011-01-010.00
52881Employee name...employee@email.com2011-01-010.00
52880Employee name...employee@email.com2011-01-010.00
52879Employee name...employee@email.com2011-01-010.00
52878Employee name...employee@email.com2011-01-010.00
52877Employee name...employee@email.com2011-01-010.00
52876Employee name...employee@email.com2011-01-010.00
52875Employee name...employee@email.com2011-01-010.00
52874Employee name...employee@email.com2011-01-010.00
52873Employee name...employee@email.com2011-01-010.00
52872Employee name...employee@email.com2011-01-010.00
52871Employee name...employee@email.com2011-01-010.00
52870Employee name...employee@email.com2011-01-010.00
52869Employee name...employee@email.com2011-01-010.00
52868Employee name...employee@email.com2011-01-010.00
52867Employee name...employee@email.com2011-01-010.00
52866Employee name...employee@email.com2011-01-010.00
52865Employee name...employee@email.com2011-01-010.00
52864Employee name...employee@email.com2011-01-010.00
52863Employee name...employee@email.com2011-01-010.00
52862Employee name...employee@email.com2011-01-010.00
52861Employee name...employee@email.com2011-01-010.00
52860Employee name...employee@email.com2011-01-010.00
52859employee@email.com2011-01-010.00
52857Employee name...employee@email.com2011-01-010.00
52852rachunekemployee@email.com2011-01-010.00
52851Employee name...employee@email.com2011-01-010.00
52850Employee name...employee@email.com2011-01-010.00
52849Employee name...employee@email.com2011-01-010.00
52848Employee name...employee@email.com2011-01-010.00
52847Employee name...employee@email.com2011-01-010.00
52846Employee name...employee@email.com2011-01-010.00
52845Employee name...employee@email.com2011-01-010.00
52844Employee name...employee@email.com2011-01-010.00
52843Employee name...employee@email.com2011-01-010.00
52842Employee name...employee@email.com2011-01-010.00
52841Employee name...employee@email.com2011-01-010.00
52840Employee name...employee@email.com2011-01-010.00
52839Employee name...employee@email.com2011-01-010.00
52838Employee name...employee@email.com2011-01-010.00
52837Employee name...employee@email.com2011-01-010.00
52836Employee name...employee@email.com2011-01-010.00
52835Employee name...1employee@email.com2011-01-010.00
52834Employee name...employee@email.com2011-01-010.00
52832Employee name...employee@email.com2011-01-010.00
52827tataemployee@email.com2011-01-130.00
52824fggtremployee@email.com2011-01-010.00
52822Employee name...employee@email.com2011-01-010.00
52821yyyy rghfgemployee@email.com2011-01-010.00
52820saya juga bisa employee@email.com2011-01-010.00
52819dfsdfsdfsdfsdfsdfdas@ggg.com2011-01-010.00
52817Employee name...employee@email.com2011-01-010.00
52816ABCemployee@email.com2011-01-150.00
52815Employee name...employee@email.com2011-01-010.00
52814gdfgfdgdgdgfdgemployee@email.com2011-01-010.00
52813Rrremployee@email.com2011-01-010.00
52811Tyyyemployee@email.com2011-01-010.00
52810Employee name...employee@email.com2011-01-010.00
52809Employee name...employee@email.com2011-01-010.00
52808Employee name...employee@email.com2011-01-010.00
52807Employee name...employee@email.com2011-01-010.00
52806Testemployee@email.com2011-01-010.00

Make sure jQuery is imported in your document before ezEditTable.js. Example of jQuery dependency:

			
			

Configuration object:

			//ezEditTable configuration object			
			var ezConfig = {
				editable: true,
				ajax: true,
				auto_save: true,
				auto_save_model: 'row',
				default_selection: 'both',
				editor_model: 'cell',
				editable_on_keystroke: true,
				form_submit_interval: 999, //interval separating data submissions to prevent server`s overload security policy
				cell_editors:[
					{ type: 'none' },
					{ type: 'input', attributes:[['title', 'First name and last name']] },
					{ type: 'input', attributes:[['title', 'email address']] },
					{ type: 'custom', target: 'datePick' },
					{ type: 'input', attributes:[['maxLength', 10], ['title', '10 digits max.\n numbers with 2 decimal places only']], css:'alignRight' },
					{ type: 'boolean' }
				],
				actions:{
					'update': {
						uri: 'php/json.update.record.php', form_method: 'POST',
						param_names: ['id','name','email','startdate','salary','active']
					},
					'insert': {
						uri: 'php/json.insert.record.php', form_method: 'POST',
						param_names: ['id','name','email','startdate','salary','active'],
						default_record: [
							'', 'Employee name...', 'employee@email.com', '2011-01-01','0', 
							'<input type="checkbox" checked />'
						]
					},
					'delete': { 
						uri: 'php/json.delete.record.php', form_method: 'POST', 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){
					if(cell.cellIndex == 3){ 
						if(editor.innerHTML == '') setPickerDate();
						//properties added for date picker onselected delegate (setOnSelectedDelegate)
						datePicker.eg_obj = o; 
						datePicker.eg_cell = cell;
						datePicker.eg_editor = editor;
					} else cell.innerHTML = '';
					cell.appendChild(editor);
					editor.style.display = ''; 
				},
				close_custom_editor: function(o, cell, editor){ 
					if(cell.cellIndex == 3){
						editor.style.display = 'none';
						document.body.appendChild(editor);
					}
				},
				//We define here how to retrieve the custom editor value
				get_custom_editor_value: function(o, editor, colIndex){
					var strDate;
					if(colIndex == 3){//Date picker
						var obj = datePicker.getSelectedDay();
						var m = (obj.month.toString().length==1 ? '0' + obj.month : obj.month);
						var d = (obj.day.toString().length==1 ? '0' + obj.day : obj.day);
						strDate = obj.year+'-'+m+'-'+d;
					}				
					return strDate;
				},
				//We define here how to set the custom editor value
				set_custom_editor_value: function(o, editor, colIndex, val){
					if(colIndex == 3){ 
						var date = et_FormatDate(val, 'YMD');
						datePicker.setSelectedDay({ year:parseInt(date.getFullYear()), month:parseInt(date.getMonth()+1), day:parseInt(date.getDate()) });
					}
				}
			}
		

Below the PHP code used for the CRUD operations in this demo:

Insert:
			<?php
				header("content-type: application/json");
				header("Cache-Control: no-cache");
				
				$ret = array();
			
				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'];
					$rowId = $_POST["rowId"]; // rowId param is appended to all insert calls
					if($active == 'true') $active = 1;
					else $active = 0;
					
					connect_db();
					$query = "INSERT INTO ".TBL_DEMO_EMPLOYEE." ".
								" VALUES('0','$name','$email','$startdate','$salary',null, null,". 
								"'$ip', null, null, NOW(), null, null, $active, 0)";
					$result = mysql_query($query);
			
					if(mysql_affected_rows() > 0) {
						//last inserted record id
						$insert_id = mysql_insert_id();
						$ret = array( "result" => array("success" => 1, "description" => "Record successfully created.", "id" => $insert_id) );
					} else {
						$ret = array( "result" => array("success" => 0, "description" => "No record(s) affected.", "id" => null) );
					}
					
					close_db();
				} else {
					$ret = array( "result" => array("error" => 1, "description" => "Expected parameter(s) not found.") );
				}
				
				echo json_encode($ret);
			?>		
		
Update:
			<?php
				header("content-type: application/json");
				header("Cache-Control: no-cache");
			
				$ret = array();
			
				if(isset($_POST["rowId"]) && isset($_POST["name"]) && isset($_POST["email"])){
					$id = $_POST["id"];
					$rowId = $_POST["rowId"];
					if($id == ""){ //if id empty then id is retrieved from rowId
						$id = str_replace("tr", "", $rowId);
					}
					$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'";
					$result = mysql_query($query);
					
					if(mysql_affected_rows() > 0) {
						$ret = array( "result" => array("success" => 1, "description" => "Record successfully updated.", "id" => $id) );
					} else {
						$ret = array( "result" => array("success" => 0, "description" => "No record(s) affected.", "id" => $id) );
					}
			
					close_db();
				} else {
					$ret = array( "result" => array("error" => 1, "description" => "Expected parameter(s) not found.") );
				}
				
				echo json_encode($ret);
			?>
		
Delete:
			<?php
				header("content-type: application/json");
				header("Cache-Control: no-cache");
				
				$ret = array();
				
				if(isset($_POST["rowId"])){
					$id = isset($_POST["id"]) ? $_POST["id"] : str_replace("tr", "", $_POST["rowId"]);
					$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'";
					$result = mysql_query($query);
					
					if(mysql_affected_rows() > 0) {
						$ret = array( "result" => array("success" => 1, "description" => "Record successfully deleted.", "id" => $id) );
					} else {
						$ret = array( "result" => array("success" => 0, "description" => "No record(s) affected.", "id" => $id) );
					}
					
					close_db();
				} else {
					$ret = array( "result" => array("error" => 1, "description" => "Expected parameter(s) not found.") );
				}
				
				echo json_encode($ret);
			?>
		

Top of page
E.n.j.o.y.  ads-free content!