Forum

July 12th, 2025
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
How to pass data of the cell from jqGrid to the "cellurl"
08/09/2010
14:30
Avatar
sibbim
Member
Members
Forum Posts: 7
Member Since:
08/09/2010
sp_UserOfflineSmall Offline

Hi 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:

cellurl: 'se/ref_mgmnt_save.php',

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:

$queryUpdate = "UPDATE table SET ".$celname."='".$value."' WHERE table_id='".$rowid."';";

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 Cry

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.

function loadRefMgmnt(tableName){
    
    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:

<?php
    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

08/09/2010
16:18
Avatar
sibbim
Member
Members
Forum Posts: 7
Member Since:
08/09/2010
sp_UserOfflineSmall Offline

It's getting clearer now...

$celname     = isset($_POST['orig_country']) ? $_POST['orig_country']: false;

I'm able to get the value when I use the name of the column directly.

Now I just need the column name itself and the rowid - any ideas on that?

08/09/2010
16:26
Avatar
sibbim
Member
Members
Forum Posts: 7
Member Since:
08/09/2010
sp_UserOfflineSmall Offline

and thats the way to get the id 😉

$rowid         = isset($_POST['id']) ? $_POST['id']: false;

only the column name is missing

08/09/2010
16:45
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

You 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 

08/09/2010
16:57
Avatar
sibbim
Member
Members
Forum Posts: 7
Member Since:
08/09/2010
sp_UserOfflineSmall Offline

Hi 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

ajaxCellOptions: {data: "tableName="+tableName+"&tableNameId="+tableNameId}

This works pretty good - BUT... this overwrites the jqGrid parameters (Col=NewData&id=2&oper=edit)

I also tried it this way:

ajaxCellOptions: {data: "tableName="+tableName+"&tableNameId="+tableNameId+"&rowid="+rowid+"&cellname="+cellname+"&value="+value},

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

08/09/2010
17:50
Avatar
sibbim
Member
Members
Forum Posts: 7
Member Since:
08/09/2010
sp_UserOfflineSmall Offline

After all - it was pretty easy 😉

        beforeSubmitCell : function(rowid,celname,value,iRow,iCol) {
            //alert (rowid +"/"+celname+"/"+value+"/"+iRow+"/"+iCol);
            return {tableNameId:tableNameId,tableName:tableName};
        },

I hope I could help you 😉

08/09/2010
18:00
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

If 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. 🙂

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information