2010-04-23 37 views
1

我是基于这个文档 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:cell_editing上CellEdit jqGrid的检索网格编号

试图做一个单元格内编辑我有两个问题:

  1. 我怎样才能得到我行的指数发布到服务器: 我得到发布的信息如下:细胞 b的 一)值)ROWID

的东西是THA t rowId不帮助我。我需要显示的信息的实际ID,以便我可以使用该ID进行服务器更新。

colNames:[ 'ID', 'Codigo', '农布雷'],

colModel: {名称: 'ID',索引: 'ID',宽度:50,对齐: '左' ,隐藏的:真},

{名称: 'Codigo',索引: 'Codigo',宽度:55,对齐: '左',编辑:真,editrules: {号码:真}},

{name:'Nombre',index:'Nombre',width:200,align:'left'}],

我需要'Id'做我的更新。

2.我不明白在文档中如何管理服务器的错误,所以我可以显示错误消息。

非常感谢!

注:

一)我已经问trirand的论坛,但没有人回答我的。 b)如果有人这样做了,如果帮我粘贴代码会有帮助。

三)我工作的MVC 2 Asp.net

回答

0

大多是你在线编辑或表单编辑,而不是单元格编辑。我建议您切换到两种现代表单编辑之一,或者您可以使用

  1. 信息RowId已经是'Id'列的值。 getInd(rowid,false)方法返回由id = rowid指定的网格表中的行的索引。
  2. 为了能够显示从服务器返回的错误,您需要知道在错误情况下从服务器返回的数据的格式。如果从服务器返回的错误有,例如,JSON格式{"Detail":"error text"}(从WFC服务错误),你可以这样定义的jqGrid的loadError参数:

    loadError:功能(XHR,ST,ERR){警报(errorTextFormat(XHR)) ; }

凡解码错误消息,可能看起来像

var errorTextFormat = function (data) { 
    var str = data.responseText.substr(0, 10); 
    if (str === '{"Detail":') { 
     var errorDetail = jQuery.parseJSON(data.responseText); 
     var s = "Error: '"; 
     s += data.statusText; 
     s += "'. Details: "; 
     s += errorDetail.Detail; 
     return s; 
    } else { 
     var res = "Status: '"; 
     res += data.statusText; 
     res += "'. Error code: "; 
     res += data.status; 
     return res; 
    } 
}; 

你可以用它来解码行编辑的错误相同的功能(至少内嵌编辑或表单编辑)errorTextFormat功能。 ASP.NET MVC主要返回HTML格式的消息,因此您的错误解码功能应该是另一种。我不会像其他人一样使用单元格编辑功能,因此无法帮助您或在单元格编辑中自定义错误消息。

+0

谢谢奥列格,我会尝试内联编辑。我只是对单元格编辑有兴趣,因为我只需要对该单元格进行编辑。 但我的问题没有得到回答。我如何发送'Id'到服务器? – Sanchitos 2010-04-27 19:46:08

+0

刚发现,你问我一次。可能你的问题现在已经解决了。也许你现在发现,在一个修改后发送的数据例如列'Nombre'看起来像是'Nombre = NewData&id = 2&oper = edit',所以你所要求的列的识别问题不存在。您同时具有rowId和列名称(与“列”Id'“相同)。 – Oleg 2010-09-08 23:57:18

0

Q1: 您可以使用Key:真正的,可编辑:真正的,在colModel

{ key:true, name: 'Id', index: 'Id', width: 50, align: 'left', editable: true, hidden:true} 

    Then in add/edit method (add beforeShowForm method in add/edit method), you have to explicitly hide this field the field of id inside of beforeShowForm method 
    $('#tr_Id').hide(); 

    i.e 
     beforeShowForm: function (e) { 
        $('#tr_Id').hide(); 
       } 

Q2:

add 'afterSubmit' method in add/edit/delete method , i'm using Web api Server , 
    i.e 
     afterSubmit: function (response) { 
      if (response.statusText == 'Created') { 
       // alert("Create Successfully") 
       ShowMessage("Add Successfully", 'Success'); 
       //reload the grid 
       $(this).jqGrid("setGridParam", { datatype: 'json' }); 
       return [true]; 
      } 
      else { 
       ShowMessage("Operation Failed", 'Error'); 
       return [false]; 
      } 

     }, 

我希望这会为你工作。仍然ü需要任何形式的帮助,请在下面评论