0

I have create the the jqgrid which loads the data from the server , i am able to view the data in a grid , but when i try to extend and fire up onclickSubmit of $.jgrid.del i am not be able to get the actual record id (which is in my case it is 101 , 102 ) instead of that it returns 1 , 2 , may be a row index id.

JqGrid

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 Response

{
  "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": "",

    }
  ]
}

Well specifying id in json reader solved my problem in deleting record , but when i edit the record my postdata argument contains

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

and when i try to access it as postdata.id or postdata.e_info_id it returns undefined , here is the onclickSubmit of edit

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


        options.url = options.editurl +'/' + encodeURIComponent(postdata.id);
    }
Hunt
  • 8,215
  • 28
  • 116
  • 256
  • About `onclickSubmit`: Please read [my answer](http://stackoverflow.com/a/9923417/315935) on your previous question carefully. The property of `postdata` which hold the `id` has *not* the name `id`. It will be `eventGrid_id` in your case. The property name are constructed from the `id` of the grid and `"_id"` text: `gridId + "_id"`. – Oleg Mar 29 '12 at 14:18
  • If you would add "jquery" or "javascript" tag to the question the code will be marked in JavaScript specific colors. – Oleg Mar 29 '12 at 15:46

2 Answers2

2

Looking at the docs here I think you should specify your id property name in the jsonReader.

jsonReader : { repeatitems: false, id: "e_info_id" }
Christian
  • 1,258
  • 10
  • 11
  • +1 from me. Your answer is absolutely correct. I just added additional information in my answer. – Oleg Mar 29 '12 at 14:21
  • @Hunt: You should vote up such answers too if you want to receive answers on your questions in the future. You can read in [FAQ](http://stackoverflow.com/faq#howtoask) very simple rule: "**As you see new answers to your question, vote up the helpful ones by clicking the upward pointing arrow to the left of the answer**". Typically one should vote up all answers on your own which was in any way helpful. Voting answers on other questions help other visitors of the same page. – Oleg Mar 29 '12 at 14:25
0

If you use jsonReader: { repeatitems: false } jqGrid don't know which values it should use as so named rowid. The rowid is the value of id attribute of <tr> elements in the grid.

To fix the problem you have two options:

  1. To define key: true property in the e_info_id column.
  2. To use id: "e_info_id" in jsonReader (see the answer of Christian)

The default value of id property in the jsonReader is 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.

Oleg
  • 220,925
  • 34
  • 403
  • 798