如何在删除行时动态传递所有jqgrid单元格值

发布于 2024-09-07 05:25:18 字数 2102 浏览 7 评论 0原文

我对 JQGrid 很陌生,所以如果这是一个非常“废话”的问题,我提前道歉。

情况是当我删除网格中的一行时,jqgrid 只将参数 id 传递给 editurl。但是,在某些情况下,我需要多个 id 参数来删除一行,例如对于这样的网格:

{UserID, Message} => {(user1, "hello"),(user1, "hola"),(user2,"hi")}

如果我只想删除 (user1, "hello") 行,我需要 JQGrid 传递参数 UserID= user1 和 Message="hello" 否则 (user1, "hello") 和 (user1, "hola") 将被删除。

我已经尝试在删除之前使用 onClickSubmit 参数修改 url:

onclickSubmit: function(rp_ge, postdata){
    rp_ge.url = 'RowManipulator.php?UserID='+$('#grid').getCell(postdata, 'UserID')+
                '&Message='+$('#grid').getCell(postdata,'Message');

但是结果 url(检查 firebug 后)是:

RowManipulator.php?UserID=user1&Message=false

而不是 RowManipulator.php?UserID=user1&Message="hello"。看来消息参数无法传递。

有谁知道如何实现我的意图?任何帮助将不胜感激

更新: 这是 jquery 代码:

jQuery(document).ready(function(){
    jQuery("#list").jqGrid(
        { url:'DataFetcher.php',
          datatype: 'xml',
          mtype: 'GET',
          colNames:['UserId','Message'],
          colModel:[
              {name:'UserId',index:'UserId',width:75, editable:false,align: 'left'},
              {name:'Message',index:'Message',width:200, editable:true,align: 'left'}
          ],
          pager: jQuery('#pager'),
          rowNum:10,
          rowList:[10,20,30],
          sortname:'UserId',
          sortorder: "asc",
          viewrecords: true,
          imgpath: 'jqgrid/css/images',
          caption: 'MESSAGE',
          editurl:'RowManipulator.php',
          height: 350,
          width: 1000});
     jQuery("#list").jqGrid('navGrid','#pager',{},
         {height:280,reloadAfterSubmit:true},
         {height:280,reloadAfterSubmit:true},
         {onclickSubmit: function(rp_ge, postdata){
             rp_ge.url = 'RowManipulator.php?UserId='
                         $('#list').getCell(postdata, 'UserId') &&
                         Message=$('#list').getCell(postdata,Message);
         },
         reloadAfterSubmit:true},
         {sopt:['cn','eq']})

I'm very new with JQGrid, so I apologize in advance if this a very 'duh' question..

The case is when I delete a row in the grid, jqgrid only pass the parameter id to the editurl. However, there are cases when I need more than one id parameter to delete a row, for instance for grid like this:

{UserID, Message} => {(user1, "hello"),(user1, "hola"),(user2,"hi")}

If i want to only delete the (user1, "hello") row, I need JQGrid to pass the parameter UserID=user1 and Message="hello" otherwise the (user1, "hello") and (user1, "hola") will be deleted.

I alreadt tried to modify the url before deleting by using onClickSubmit parameter:

onclickSubmit: function(rp_ge, postdata){
    rp_ge.url = 'RowManipulator.php?UserID='+$('#grid').getCell(postdata, 'UserID')+
                '&Message='+$('#grid').getCell(postdata,'Message');

However the resulted url (after checking on firebug) is:

RowManipulator.php?UserID=user1&Message=false

instead of RowManipulator.php?UserID=user1&Message="hello". It seems that the message paramater can't be delivered.

Does anyone have any idea how to achieve what I intended to? Any help will be very appreciated

Updated:
Here is the jquery code:

jQuery(document).ready(function(){
    jQuery("#list").jqGrid(
        { url:'DataFetcher.php',
          datatype: 'xml',
          mtype: 'GET',
          colNames:['UserId','Message'],
          colModel:[
              {name:'UserId',index:'UserId',width:75, editable:false,align: 'left'},
              {name:'Message',index:'Message',width:200, editable:true,align: 'left'}
          ],
          pager: jQuery('#pager'),
          rowNum:10,
          rowList:[10,20,30],
          sortname:'UserId',
          sortorder: "asc",
          viewrecords: true,
          imgpath: 'jqgrid/css/images',
          caption: 'MESSAGE',
          editurl:'RowManipulator.php',
          height: 350,
          width: 1000});
     jQuery("#list").jqGrid('navGrid','#pager',{},
         {height:280,reloadAfterSubmit:true},
         {height:280,reloadAfterSubmit:true},
         {onclickSubmit: function(rp_ge, postdata){
             rp_ge.url = 'RowManipulator.php?UserId='
                         $('#list').getCell(postdata, 'UserId') &&
                         Message=$('#list').getCell(postdata,Message);
         },
         reloadAfterSubmit:true},
         {sopt:['cn','eq']})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感悟人生的甜 2024-09-14 05:25:18

该行

rp_ge.url = 'RowManipulator.php?UserId='
                         $('#list').getCell(postdata, 'UserId') &&
                         Message=$('#list').getCell(postdata,Message);

有语法错误。 postdata 是否尚未包含“UserId”?然后 $('#list').getCell(postdata, 'UserId') 将为您返回 postdata

尝试使用

rp_ge.url = 'RowManipulator.php?UserId=' +
             $('#list').getCell(postdata, 'UserId') +
             'Message=' + $('#list').getCell(postdata,'Message');

或更好地使用

rp_ge.url = 'RowManipulator.php?' +
            jQuery.param({UserId: $('#list').getCell(postdata, 'UserId'),
                          Message: $('#list').getCell(postdata, 'Message')});

The line

rp_ge.url = 'RowManipulator.php?UserId='
                         $('#list').getCell(postdata, 'UserId') &&
                         Message=$('#list').getCell(postdata,Message);

has syntax errors. Is postdata not already contain the 'UserId'? Then $('#list').getCell(postdata, 'UserId') will gives you back postdata.

Try with

rp_ge.url = 'RowManipulator.php?UserId=' +
             $('#list').getCell(postdata, 'UserId') +
             'Message=' + $('#list').getCell(postdata,'Message');

or better with

rp_ge.url = 'RowManipulator.php?' +
            jQuery.param({UserId: $('#list').getCell(postdata, 'UserId'),
                          Message: $('#list').getCell(postdata, 'Message')});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文