0

I have some problem for deleting a row in jqGrid.

My row consists of two primary keys which are email and idms_module. These two keys are needed for deleting the row, because one email can have two or more idms_module.

Here's the syntax:

   jQuery("#grid-uac").jqGrid({
                mtype:'GET',
                url:'functions/get_useraccess.php',
                editurl:'functions/edit_useraccess.php',
                datatype: "JSON",
                colNames:['User Email','Module Access','Level Access'],
                colModel:[
                    {name:'user_email', width:300, editable:true, key:true},
                    {name:'module_access', width:550,editable:true, key:true,edittype:'select',editoptions:{dataUrl:'functions/get_modusracc.php'}},
                    {name:'level_access',width:100,editable:true,edittype:'select',editoptions:{value:"0:read only;1:read write"}}
                ],
                loadComplete: function () {
                alert("OK");
                },    
                loadError: function (jqXHR, textStatus, errorThrown) {
                    alert('HTTP status code: ' + jqXHR.status + '\n' +
                          'textStatus: ' + textStatus + '\n' +
                          'errorThrown: ' + errorThrown);
                    alert('HTTP message body (jqXHR.responseText): ' + '\n' + jqXHR.responseText);
                },
                rowNum:10,
                rowList:[5,10,15],
                pager: '#pager-uac',
                sortname: 'user_email',
                viewrecords: true,
                jsonReader: **{id: "user_email", id2 or some var : "module_access"}**, 
                sortorder: "asc",
                gridview: true,
                autoencode:true,
                caption:"Inventory User Access Role"
            });

So for example I want to delete a row, which consists of email: admin@test.com and idms_module: 6

The part of the php code is:

  $email  = $_REQUEST['id'];
  $modules= $_REQUEST['another var'];

  $query = DELETE FROM table WHERE email= $email AND module = $modules

I have successfully gotten the email from the id but haven't got any ideas on how to get the 'another var'

DisplayName
  • 3,093
  • 5
  • 35
  • 42
randytan
  • 1,029
  • 5
  • 23
  • 52

2 Answers2

1

First of all one common remark about the database design. Typically one use integer values in the database. One uses IDENTITY or AUTO_INCREMENT words during definition of such column. One uses the integer column as PRIMARY KEY typically. One adds additionally UNIQUE CONSTRAINT on the columns which can't contains duplicates. UNIQUE CONSTRAINT adds index on the column so the searching by the column will be quickly. I think that all tables in the database which I used in productive databases follow the rule.

You you don't can to change anything on the server side then you can do the following. You can't use the property key:true in more as one column of colModel. You can't use it in one column like user_email if you can have more as one row which the same data. What you can do is for example: usage of composed id value which consist from user_email, module_access value and some separator. For example in case of "test@mydomain.com" and "module1" you can use test@mydomain.com@module1 as the id. The second @ can't be in e-mail any you can use it as separator. One more variant of encoding will be Base64 encoded (or just HEX encoded) value of user_email, the character _ and Base64 encoded (or HEX encoded) value of module_access. jqGrid will send you the rowid during Delete operation and you will be able to decode the rowid to user_email and module_access.

One more option which you have is usage any rowid, but send both 'user_email' and 'module_access' together with the rowid. You can use serializeDelData or onclickSubmit callbacks (see the documentation) or you delData to extend the data. The callbacks get rowid as the input. You can use the getCell or getRowData to retry 'user_email' and 'module_access' and just extend the data which will be sent to the server. The answer shows the same for Edit operation. Simple renaming of callbacks will show you the . Another examples you will find in the answer or in this one.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • hi @oleg, thanks for your answer, i've decided to change the way for deletion function. Because, i don't have rights to change the database. – randytan Jul 05 '13 at 01:12
0

Can your server provide an additional data attribute consisting in email+id? You could then declare it as the id column (hidden) in jqgrid, and have the server untokenize it when you send it back?

Pablo
  • 167
  • 1
  • 2
  • 13