Forum
Topic RSS
14:30
08/09/2010
OfflineHi Everybody,
I'm pretty new to jqGrid and I understand already lot of thinks. However I'm not able to pass
the data after a cellchange to my update php script.
View a few words:
1. I build the jqGrid with the option:
I can see the grid with all data and when I click on a cell it becomes editable.
2. After pressing the Return-Key I want this data to be stored in the MySQL database:
Well, and this is my problem. The PHP-File "se/ref_mgmnt_save.php" is called but the data is not stored in the database because the PHP script doesn't know the celname (column name from grid), value (the new value in this column) and the rowid (the primary key).
The Wiki says (http://www.trirand.com/jqgridw.....ll_editing)
"The rowid and the cell content are added to the url as name:value pairs. For example, if we save the cell named mycell,{id: rowid, mycell: cellvalue} is added to the url."
Sorry, but I don't have any idea what is ment by this and how I can refer to the data in my PHP-Script. I think without a hint from your site I'm totally lost 
More detailed - my Javascript file:
getColumnHeader is just a function to populate the jqgrid with all columns from the corresponding table. This works pretty fine.
var tableNameId = tableName + "_id";
var columnHeader = getColumnHeader(tableName, "", "");
var columnHeader2 = getColumnHeader2(tableName, "", "");
$("#ref_mgmnt").jqGrid({
url:'se/ref_mgmnt.php',
datatype: "json",
height: 450,
width: 1100,
colNames: columnHeader2,
colModel: columnHeader,
rowNum: 50,
rowTotal: 2000,
rowList : [20,30,50],
scroll:1,
loadonce:true,
mtype: "GET",
gridview: true,
pager: '#ref_mgmnt_pager',
sortname: 'item_id',
viewrecords: true,
sortorder: "asc",
caption: "Reference data",
cellEdit: true,
cellurl: 'se/ref_mgmnt_save.php',
afterSubmitCell: function(serverresponse, rowid, cellname, value, iRow, iCol) {
alert (serverresponse.responseText);
},
beforeSubmitCell : function(rowid,celname,value,iRow,iCol) {
var varCellUrl = 'se/ref_mgmnt_save.php';
//alert (rowid +"/"+celname+"/"+value+"/"+iRow+"/"+iCol);
}
});
$("#ref_mgmnt").jqGrid('navGrid','#ref_mgmnt_pager',{del:false,add:true,edit:false},{},{},{},{multipleSearch:true});
}
2. And finally my PHP-File:
require '../settings.inc.php';
require BASE_DIR.'/class/mysql.class.php';
$celname = isset($_POST['celname']) ? $_POST['celname']: false;
$value = isset($_POST['value']) ? $_POST['value']: false;
$rowid = isset($_POST['rowid']) ? $_POST['rowid']: false;
try {
$sql = new mysql ($_SESSION['db_server'], $_SESSION['db_user'], $_SESSION['db_pass'], $_SESSION['db_name']);
$queryUpdate = "UPDATE table SET ".$celname."='".$value."' WHERE table_id='".$rowid."';";
$result = $sql->mysqlGetData ($queryUpdate);
} catch (Exception $e) {
echo $e->getMessage();
exit();
}
$total = mysql_affected_rows();
// Return JSON data
$json = array();
$json['queryUpdate'] = $queryUpdate;
// PHP json_encode not supported < 5.1.6
require BASE_DIR.'/class/json_encode.php';
echo json_encode($json);
try {
$sql->mysqlCloseDb();
} catch (Exception $e) {
echo $e->getMessage();
exit();
}
?>
Thanks,
Sebastian
16:45
10/08/2009
OfflineYou can use Fiddler to see all data which will be send or returned from the server. If you use it with the localhost you should use ipv4.fiddler instead of the localhost.
The data look like
Col=NewData&id=2&oper=edit
where Col is the column name like you define it in the colModel, NewData is the value which the user enter in the cell, the meaning of id and oper is clear.
Regards
Oleg
16:57
08/09/2010
OfflineHi Oleg,
thanks for your reply - I found the other parameter...
...However - I also need the table name and the primary key. My idea was to use
This works pretty good - BUT... this overwrites the jqGrid parameters (Col=NewData&id=2&oper=edit)
I also tried it this way:
But it seems that the variables are not known at this stage - and this is why it doesn't show the grid than.
Nevertheless, is this the right way to pass additional parameters to the PHP?
Thanks,
Sebastian
18:00
10/08/2009
OfflineIf your beforeSubmitCell function will returns an object it will be combined with the postdata. For example is you fill use
beforeSubmitCell : function(rowid,celname,value,iRow,iCol) {
return {tableName: "myTableName", tableNameId: "myTableNameId"}
}
then the posted data will looks like
tableName=myTableName&tableNameId=myTableNameId&Col=NewData&id=2&oper=edit
So with respect of beforeSubmitCell you can put/override any information send during cell editing.
Regards
Oleg
P.S. How could I see I write slowly as you. 🙂
Most Users Ever Online: 994
Currently Online:
20 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
Log In
Home