JqG​​rid中用于删除行的两个参数 [英] Two Parameter for Deleting A Row in JqGrid

查看:153
本文介绍了JqG​​rid中用于删除行的两个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在删除jqGrid中的行时遇到一些问题.

I have some problem for deleting a row in jqGrid.

我的行由两个主键组成,分别是email和idms_module.删除行需要使用这两个键,因为一封电子邮件可以包含两个或多个idms_module.

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.

语法如下:

   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"
            });

例如,我想删除一行,其中包含电子邮件:admin@test.com和idms_module:6

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

php代码的一部分是:

The part of the php code is:

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

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

我已经成功地从id中获得了电子邮件,但是对如何获取另一个变种"一无所知

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

推荐答案

首先是有关数据库设计的常见说明.通常在数据库中使用整数值.在此类列的定义过程中,使用IDENTITYAUTO_INCREMENT字.通常将整数列用作PRIMARY KEY.可以在不能包含重复项的列上另外添加UNIQUE CONSTRAINT. UNIQUE CONSTRAINT在该列上添加索引,因此该列的搜索将很快.我认为我在生产型数据库中使用的数据库中的所有表都遵循该规则.

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.

您无法在服务器端进行任何更改,则可以执行以下操作.您不能将属性key:true用作colModel的一列.如果同一行中可以包含更多行,则不能在user_email这样的一列中使用它.例如,您可以做的事情是:使用由user_emailmodule_access值和一些分隔符组成的id值组成的用法.例如,对于"test@mydomain.com""module1",您可以使用test@mydomain.com@module1作为ID.第二个@不能存在于电子邮件中,您可以将其用作分隔符.编码的另一种形式是 Base64 编码(或只是十六进制编码)的值user_email ,字符_module_access的Base64编码(或HEX编码)值.在删除操作期间,jqGrid将向您发送行ID,您将能够将行ID解码为user_emailmodule_access.

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.

您还有一个选择是使用 any 行标识符,但同时将'user_email''module_access'与该行标识符一起发送.您可以使用serializeDelDataonclickSubmit回调(请参见文档),或者您delData扩展数据.回调获取rowid作为输入.您可以使用getCellgetRowData重试'user_email''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.

这篇关于JqG​​rid中用于删除行的两个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆