0

我已经创建了从服务器加载数据的 jqgrid,我可以在网格中查看数据,但是当我尝试扩展和启动时onclickSubmit$.jgrid.del我无法获得实际的记录 ID(在我的情况是 101 、 102 )而不是它返回 1 、 2 ,可能是行索引id。

JqG​​rid

jQuery("#eventGrid").jqGrid({
    url:"/eventAllInfo",
    datatype: "json",
    restful:  true,
    mtype: 'GET',
    width:900,

    colNames:['id','title', 'description'],
    colModel:[ 
        {name:'e_info_id',index:'e_info_id', width:60, sorttype:"int",editable:true,editoptions:{size:10}},
        {name:'e_meta_title',index:'e_meta_title', width:90,editable:true,editoptions:{size:10}},
        {name:'e_meta_description',index:'e_meta_description', width:100,editable:true,editoptions:{size:10}},          
    ],
    rowNum:10, rowList:[10,20,30], 
    jsonReader : { repeatitems: false },
    pager: '#pager',        
    caption: "Show Events"
});

JSON 响应

{
  "success": true,
  "message": "Records Retrieved Successfully -EventAllInfo",
  "page": "1",
  "total": 1,
  "records": "2",
  "rows": [
    {
      "e_info_id": "101",
      "e_meta_title": "Oracle Business Summit",
      "e_meta_description": null,
      "e_meta_img": null,
      "e_meta_video": null,

    },
    {
      "e_info_id": "102",
      "e_meta_title": "Expo 2014 - Environment",
      "e_meta_description": "",
      "e_meta_img": "",
      "e_meta_video": "",

    }
  ]
}

在 json reader 中指定 id 解决了我删除记录的问题,但是当我编辑记录时,我的 postdata 参数包含

e_info_id: "101"
e_meta_description: ""
e_meta_title: "Oracle Business Summit"
id: "101"
oper: "edit"

当我尝试以 postdata.id 或 postdata.e_info_id 访问它时,它返回 undefined ,这是编辑的 onclickSubmit

 onclickSubmit: function (options, postdata) {
        console.log(postdata);
        console.log(postdata.id); //undefined


        options.url = options.editurl +'/' + encodeURIComponent(postdata.id);
    }
4

2 回答 2

2

查看此处的文档,我认为您应该在 jsonReader 中指定您的 id 属性名称。

jsonReader : { repeatitems: false, id: "e_info_id" }
于 2012-03-29T13:49:26.100 回答
0

如果您使用jsonReader: { repeatitems: false }jqGrid,则不知道应该使用哪些值作为命名为 rowid。rowid 是网格id中元素的属性值。<tr>

要解决此问题,您有两种选择:

  1. 在列中定义key: true属性。e_info_id
  2. id: "e_info_id"jsonReader(见Christian的回答)

id中属性的默认jsonReader值为id: "id".

It's important to know that the id value have to be unique on the page. If you for example have two grids on the page and both have information with integer ids you can have conflicts. In the case you can use idPrefix option. In the case the value of id attribute of <tr> elements will be constructed from the idPrefix (which should be different in both pages of cause) and the "standard" id.

于 2012-03-29T14:08:21.167 回答