Skip to content

Commit

Permalink
Added Edit functionality to Example 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanan Langin-Hooper committed Mar 6, 2013
1 parent 74c70dc commit 179772d
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 13 deletions.
14 changes: 14 additions & 0 deletions demo/example4.php
Expand Up @@ -23,6 +23,20 @@
$_SESSION['Example4'] = $rows;

}
elseif(isset($_GET['Edit'])){ // this is for Editing records
$rows = $_SESSION['Example4'];

unset($rows[trim($_GET['OrgEmpID'])]); // just delete the original entry and add.

$rows[$_GET['EmpID']] =
array(
'name'=>$_GET['Name']
, 'favorite_color'=>$_GET['FavoriteColor']
, 'favorite_pet'=>$_GET['FavoritePet']
, 'primary_language'=>$_GET['PrimaryLanguage']
);
$_SESSION['Example4'] = $rows;
}
elseif(isset($_GET['Delete'])){ // this is for removing records
$rows = $_SESSION['Example4'];
unset($rows[trim($_GET['Delete'])]); // to remove the \n
Expand Down
106 changes: 94 additions & 12 deletions demo/index.html
Expand Up @@ -358,7 +358,7 @@ <h2>Example 4</h2>
}, {
display : 'Name',
name : 'name',
width : 180,
width : 120,
sortable : true,
align : 'left'
}, {
Expand All @@ -370,7 +370,7 @@ <h2>Example 4</h2>
}, {
display : 'Favorite Color',
name : 'favorite_color',
width : 130,
width : 80,
sortable : true,
align : 'left',
hide : true
Expand All @@ -385,13 +385,24 @@ <h2>Example 4</h2>
name : 'Add',
bclass : 'add',
onpress : Example4
}, {
}
,
{
name : 'Edit',
bclass : 'edit',
onpress : Example4
}
,
{
name : 'Delete',
bclass : 'delete',
onpress : Example4
}, {
}
,
{
separator : true
} ],
}
],
searchitems : [ {
display : 'EmployeeID',
name : 'employeeID'
Expand Down Expand Up @@ -424,7 +435,37 @@ <h2>Example 4</h2>
});
});
}
} else if (com == 'Add') {
}
else if (com == 'Edit') {
var conf = confirm('Edit ' + $('.trSelected', grid).length + ' items?')
if(conf){
$.each($('.trSelected', grid),
function(key, value){
// collect the data
var OrgEmpID = value.children[0].innerText; // in case we're changing the key
var EmpID = prompt("Please enter the New Employee ID",value.children[0].innerText);
var Name = prompt("Please enter the Employee Name",value.children[1].innerText);
var PrimaryLanguage = prompt("Please enter the Employee's Primary Language",value.children[2].innerText);
var FavoriteColor = prompt("Please enter the Employee's Favorite Color",value.children[3].innerText);
var FavoriteAnimal = prompt("Please enter the Employee's Favorite Animal",value.children[4].innerText);

// call the ajax to save the data to the session
$.get('example4.php',
{ Edit: true
, OrgEmpID: OrgEmpID
, EmpID: EmpID
, Name: Name
, PrimaryLanguage: PrimaryLanguage
, FavoriteColor: FavoriteColor
, FavoritePet: FavoriteAnimal }
, function(){
// when ajax returns (callback), update the grid to refresh the data
$(".flexme4").flexReload();
});
});
}
}
else if (com == 'Add') {
// collect the data
var EmpID = prompt("Please enter the Employee ID","5");
var Name = prompt("Please enter the Employee Name","Mark");
Expand Down Expand Up @@ -539,7 +580,7 @@ <h2>Example 4</h2>
}, {
display : 'Name',
name : 'name',
width : 180,
width : 120,
sortable : true,
align : 'left'
}, {
Expand All @@ -551,7 +592,7 @@ <h2>Example 4</h2>
}, {
display : 'Favorite Color',
name : 'favorite_color',
width : 130,
width : 80,
sortable : true,
align : 'left',
hide : true
Expand All @@ -566,13 +607,24 @@ <h2>Example 4</h2>
name : 'Add',
bclass : 'add',
onpress : Example4
}, {
}
,
{
name : 'Edit',
bclass : 'edit',
onpress : Example4
}
,
{
name : 'Delete',
bclass : 'delete',
onpress : Example4
}, {
}
,
{
separator : true
} ],
}
],
searchitems : [ {
display : 'EmployeeID',
name : 'employeeID'
Expand Down Expand Up @@ -605,7 +657,37 @@ <h2>Example 4</h2>
});
});
}
} else if (com == 'Add') {
}
else if (com == 'Edit') {
var conf = confirm('Edit ' + $('.trSelected', grid).length + ' items?')
if(conf){
$.each($('.trSelected', grid),
function(key, value){
// collect the data
var OrgEmpID = value.children[0].innerText; // in case we're changing the key
var EmpID = prompt("Please enter the New Employee ID",value.children[0].innerText);
var Name = prompt("Please enter the Employee Name",value.children[1].innerText);
var PrimaryLanguage = prompt("Please enter the Employee's Primary Language",value.children[2].innerText);
var FavoriteColor = prompt("Please enter the Employee's Favorite Color",value.children[3].innerText);
var FavoriteAnimal = prompt("Please enter the Employee's Favorite Animal",value.children[4].innerText);

// call the ajax to save the data to the session
$.get('example4.php',
{ Edit: true
, OrgEmpID: OrgEmpID
, EmpID: EmpID
, Name: Name
, PrimaryLanguage: PrimaryLanguage
, FavoriteColor: FavoriteColor
, FavoritePet: FavoriteAnimal }
, function(){
// when ajax returns (callback), update the grid to refresh the data
$(".flexme4").flexReload();
});
});
}
}
else if (com == 'Add') {
// collect the data
var EmpID = prompt("Please enter the Employee ID","5");
var Name = prompt("Please enter the Employee Name","Mark");
Expand Down
6 changes: 5 additions & 1 deletion demo/style.css
Expand Up @@ -156,5 +156,9 @@ h2 {
}

.flexigrid div.fbutton .delete {
background: url(images/close.png) no-repeat center left;
background: url(images/close.png) no-repeat center left;
}

.flexigrid div.fbutton .edit {
background: url(images/edit.png) no-repeat center left;
}

0 comments on commit 179772d

Please sign in to comment.