1

I'm using a JqGrid in multiselect mode and recover the user's selection. The JqGrid is defined as follow :

$("#StatusList").jqGrid({
         url: '@Url.Action("UpdateStatusList", "Inventory")',
         datatype: 'json',
         mtype: 'GET',
         colNames: ['Status', 'statusId'],
         colModel: [
          { name: 'Status', index: 'Status', align: 'left', sortable: false },
          { name: 'statusId', index: 'statusId', hidden: true}]
});

I don't have any issue for all the communication between the server and the client. Everything works fine. But I feel like I am duplicating data when filling the JqGrid with this function that sends the JSON data :

  public ActionResult UpdateStatusList()
  {
     var jsonData = new
     {
        rows = (from status in DatabaseInMemory.WoodStatus.GetEntities()
                select new
                {
                   i = status.ID,
                   cell = new string[] { status.Name,
                              status.ID.ToString() }
                }).ToArray()
     };
     return Json(jsonData, JsonRequestBehavior.AllowGet);
  }

As you can see the id is passed two times : - for the JSON Id. - for the hidden column that helps me recover the id from the grid.

Back to the client, the JSON Id is not hold in the selarrrow property. This property holds ids based on position in the grid. I'm using it to get the selected data, and recover the real ids.

Is JqGrid processes and hold the id passed through JSON data, or is it lost and an hidden column is always needed to keep track of the rows?

Matthieu
  • 4,605
  • 4
  • 40
  • 60

1 Answers1

2

You should change i = status.ID to id = status.ID.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • posted a refactoring proposition for the example I took to create my website based on your answer : http://www.timdavis.com.au/code/jquery-grid-with-asp-net-mvc/ . Thanks :) – Matthieu Aug 18 '11 at 15:41
  • @Matthieu: Look at the UPDATED part of [the answer](http://stackoverflow.com/questions/5500805/asp-net-mvc-2-0-implementation-of-searching-in-jqgrid/5501644#5501644). You can download the [VS2008 demo project](http://www.ok-soft-gmbh.com/jqGrid/jqGridDemo.zip) or [VS2010 demo project](http://www.ok-soft-gmbh.com/jqGrid/jqGridDemoVS2010.zip). You can search on [the page](http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx) for "Oleg" and find my bug report. The bugs are fixed on Phil Haack' page, but not on Tim Davis's copy of his demo. – Oleg Aug 18 '11 at 15:57
  • nice, will use your answer as a reference in the future, thx! – Matthieu Aug 18 '11 at 16:01