1

I've been trying to implement a simple subgrid within jqgrid to show line items for an invoice. I finally got the subgrids to populate but each subgrid is showing the same list of line items, which is actually all of the entries in the data set.

I'm not quite sure how to debug this but here are some of my potential ideas-

  • Is it a problem with the way the json store is (not) responding to the GET queries?

  • Is it because nowhere I define what field within the subgrid data is the "foriegn key" so to speak.

  • Do I need the subGridUrl to point to json data with only the appropriate data (not every line item)

Example JSON for line items: order_id points to the id of the order

{
  "total": 1,
  "records": 6,
  "rows": [
    {
      "description": "PART X",
      "order_id": 2,
      "qty": 5,
      ... more fields ...
      "id": 1
    },
    ... more  ...
  ],
  page: 1
}

JSON for main grid items:

{
  "total": 1, 
  "records": 2,
  "rows": [
    {
      "order_no": 2,
      ... more fields ...
      "id": 2
    },
    ... more ...
  ],
  page:1
}

Applicable parts of my jqqrid script:

jQuery("#mygrid").jqGrid({
    ... cosmetic stuff for main grid ...
    url: "/my_json_url/",
    datatype: "json",
    colNames:['Order',...],
    colModel:[
        {name:'order_no', index:'order_no'},
        ...
    ],
    jsonReader: {
        repeatitems:false,
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        cell: "",
        id: "id",
        subgrid: {root: "rows", cell:"", repeatitems: false}
    },
    prmNames: {subgridid: "order_id"},
    subGrid: true,
    subGridUrl: "/json_url/to_line_items/",
    subGridModel: [{ name : ['qty','description'],
                     width: [100,100] }]
})navGrid(some options);
j_syk
  • 6,511
  • 2
  • 39
  • 56

1 Answers1

1

I suppose that the code under the URL "/json_url/to_line_items/" don't use id parameter sent by jqGrid. If the user expand the subgrid the rowid of the row will be used as additional parameter of subGridUrl. By the way I don't understand why you use id values of the grid other as the order_id. Currently the id=1 parameter will be appended to the subGridUrl in case of expanding the row with order_id=10. Is it what you want?

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I can see in firebug that the call when I click expand is sending the main row's id as a GET request `?id=value`. In my belief, this just needs to be `?order_id=value` but I'm not sure how to change the parameter name. Changing 'id' to 'order_id' in the subgrid parameters under jsonReader doesn't seem to help. – j_syk Nov 29 '11 at 14:18
  • 1
    @j_syk: To change the `id` name you should use jqGrid parameter `prmNames: {subgridid: "order_id"}` – Oleg Nov 29 '11 at 14:53
  • that did change the GET request to the correct parameter but the data isn't filtering. I've not had this problem with my json stores before... Let me poke around for a bit – j_syk Nov 29 '11 at 16:07
  • @j_syk: What do you mean that "the data isn't filtering"? Do you wean that your server part of code ignore the `order_id` parameter and return back the same data are displayed in every subgrid? You can verify additionally that you don't have any `id` duplicates in the grid. – Oleg Nov 29 '11 at 16:24
  • yes that is exactly what i mean. I only have 2 results in the subgrid data, no duplicate values. But when the `order_id=1` the json that is returned still has both items, which have values order_id=1 and order_id=2. So something is wrong, but I'm thinking it's my json and not the jqgrid at this point. – j_syk Nov 29 '11 at 16:42
  • @j_syk: Till you don't posted the definition of the jqGrid I don't know which value will be used for the rowid (`id` attribute of the `` element of the grid). You can consider to use [Subgrid as Grid](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:subgrid_as_grid) which gives you more hull control how to create and format the subgrid grid, which URL will be used for the subgrid and so on. – Oleg Nov 29 '11 at 17:23