views:

612

answers:

1

Hello,

I am having an issue with the using jqGrid with JSON data returned from the server.

I have a grid that is displaying different types of objects – and since the objects are different types, two could have the same ID. jqGrid seems to use the id field if the data to set the dom id of the row, so I end up having two rows with the same dom id.

Is there any way I can customize how jqGrid assigns ids to the table rows?

Additionally, if I am sending back JSON data that I don't want to display in the grid (for example, the URL to view the whole record) – is there any way to get at it later ? getRowData() seems to only return data displayed in TDs in the grid, not in the original JSON data. userdata seems to only work for the entire table, not for individual rows.. or am I mistaken?

Thanks for any help.

+1  A: 

In your JSON object that is coming into the jqGrid can you make your id field a different name that means something to you.

  [ { customId: 'A13' }, {customId: 'B13'} ]
  // do define two widgets A and B with the same ID of 13

To hold miscellanous data about rows you can just store them as hidden columns, these will return when you perform getRowData();

$('#myGrid').jqGrid({
   ...
   colNames: ['Title', 'Price', 'HiddenLink', 'HiddenSKU'],
   colModel: [               
               { name: 'Title', index: 'Title' },
               { name: 'Price', index: 'Price' },
               { name: 'HiddenLink', index: 'HiddenLink', hidden: true },
               { name: 'HiddenSKU' , index: 'HiddenSKU' , hidden: true }
             ],
   ...
};
Bobby Borszich
hidden: true works great for the hidden columns - thanks so much. However, how do I use the customIds returned in the JSON object? I've tried id: customId in the JSON reader and that doesn't work.
Thomas Fisher
come find me on my website and I can probably help you with that ;)
Bobby Borszich
Marked it accepted .. thanks .. upvote? :)
Bobby Borszich