Forum


Dude,
you need some server side language to handle that.
this is a simple working copy of jqgrid+cakephp(server side language PHP)
http://www.the-di-lab.com/?p=28
Try to look at the function indexedit() in Cakephp+JqGrid\\demo\\app\\controllers\\apples_controller.
This is where it does edit,delete,and add.
Hope you can get the basic idea from here.
regards
The-Di-Lab
18:18

30/05/2009

Hello,
What a great plugin! I am also having trouble getting the edited data to the server. Here's what I found, although I'm still having trouble getting it to work.
But since I have found almost no help on this after searching the web for hours, I thought I'd try to help...
I believe this should be the contents of 'someurl.php' (the example demo file has a blank one)
<?
// FETCHES THE 'USERS' TABLE DATA
if($_GET[oper]=='sel'){
// connect to the MySQL database server
include 'includes/auth.inc.php';
// ADDS NEW APP RECORD - I have 5 columns, and these are the titles
} elseif($_POST[oper]=='add') {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$userid = $_POST['userid'];
$start = $_POST['start'];
$note = $_POST['note'];
$ins = “INSERT INTO appid (fname,lname,userid,start,note) VALUES ($fname,$lname,$userid,$start,$note)”;
@mysql_query($ins) or die(”failed”);
// MODIFIES USER RECORD
} elseif($_POST[oper]=='edit') {
$id = $_POST['id'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$userid = $_POST['userid'];
$start = $_POST['start'];
$note = $_POST['note'];
$upd = “UPDATE appid SET (fname,lname,userid,start,note) VALUES ($fname,$lname,$userid,$start,$note) WHERE id=$id”;
@mysql_query($upd) or die(”failed”);
// DELETES USER RECORD AND ASSOCIATED ACCESS RELATIONSHIPS
} elseif($_POST[oper]=='del') {
$id = $_POST['id'];
$SQL = “DELETE FROM appid WHERE id=$id”;
$res = @mysql_query($SQL) or die(”failed”);
}
mysql_close($con);
?>
However, again, I have been unable to actually get this to work. I am hoping someone on this forum will give us more help?
Thanks in advance.
13:01

30/05/2009

I just got mine to work… had a few minor errors (still a newbie with PHP). The grid is awesome, works great.
I'm not sure how familiar you are with PHP, so here's my basic instructions:
To send your data to someurl.php, add the parameter to your colModel properties:
editurl: "someurl.php",
or use the navigator, which is what I did:
{add: true, edit: true, del: true, search: true}, //options
{height:200,width:600,reloadAfterSubmit:false,url:'someurl.php'}, // edit options
{height:200,width:600,reloadAfterSubmit:false,url:'someurl.php'}, // add options
{reloadAfterSubmit:false,url:'someurl.php'}, // del options
{width:600} // search options
);
I would recommend downloading Firebug (http://getfirebug.com/) for Firefox. It will show you what is being sent to the someurl.php page by jqgrid. For example, Firebug shows me this after expanding the POST url:
app | 11 |
expiration | 06-01-10 |
id | _empty |
oper | add |
user_id | 14 |
All of this is a simple form submission sent via POST. Once you can see the data you are processing, then you create your someurl.php, using this better basic example than the one above:
<?php
// Get information from entry
$id = $_POST['id']; //id field from POST above
$exp = $_POST['expiration']; //expiration field from POST above
$app_id = $_POST['app']; //app field from POST above
$user_id = $_POST['user_id']; //user_id field from POST above
// connect to the MySQL database server
include 'includes/dbconfig.inc.php';
$con = mysql_connect($dbhost, $dbuser, $dbpassword);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
@mysql_select_db($database,$con) or die(”Error connecting to db.”);
Then set your MySQL database commands to a php variable:
$upd = “UPDATE `table_name` SET app_id = '” . $app_id . “', user_id = '” . $user_id . “', expiration = '” . $exp . “' WHERE user_id='” . $id . “'”;
$del = “DELETE FROM table_name WHERE id='” . $id . “'”;
Finally, use php IF() to determine if you are adding, editing, or deleting a record based on the “operator” sent from above. I like this set up because when you try to add, edit, or delete a record, it will return “License added”, etc. in Firebug so you know if it's working.
if($_REQUEST[oper]=='add') {
if (mysql_query($add,$con))
{
echo “License added.”;
}
else
{
echo “Error adding user: ” . mysql_error();
}
// MODIFIES USER RECORD
} elseif($_REQUEST[oper]=='edit') {
if (mysql_query($upd,$con))
{
echo “User edited.”;
}
else
{
echo “Error editing user: ” . mysql_error();
}
// DELETES USER RECORD AND ASSOCIATED ACCESS RELATIONSHIPS
} elseif($_POST[oper]=='del') {
if (mysql_query($del,$con))
{
echo “User deleted.”;
}
else
{
echo “Error deleting user: ” . mysql_error();
}
}
mysql_close($con);
?>
I'm sure some PHP pro's out there could explain it a lot better, and someone may add corrections to this post, but this is working for me. I have 3 grids, including one subgrid, and struggled for quite a while to figure this out. Hopefully this will help you.
JqGrid is definitely awesome!
Most Users Ever Online: 715
Currently Online:
42 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66