Reputation: 913
I'm just starting out with jqGrid, so sorry if this is an obvious question (though I couldn't find the answer on their website anywhere).
I'm using the following method to add row data to my grid currently:
for (var i = 0; i <= mydata.length; i++) {
jQuery("#grid2").jqGrid('addRowData', i + 1, attributes[i]);
}
And the resulting HTML is this:
<tr class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" id="1" role="row"> ... </tr>
The id is currently based on the row number, but I would like to change the id to a custom definition, based on a variable in my mydata array.
For example, if my mydata array was so:
var mydata = [ { id="1", name="someName", type="typeOne" } ]
I would want my HTML output to look like this:
<tr class="..." id="typeOne"> </tr>
OR
<tr class="..." id="rowid" name="typeOne"> </tr>
How do I go about making sure addRowData method adds a custom id to my rows instead of the regular rowid?
Upvotes: 3
Views: 5331
Reputation: 2294
You might be looking for the key
attribute in colModel
options:
key : In case if there is no id from server, this can be set as as id for the unique row id. Only one column can have this property. If there are more than one key the grid finds the first one and the second is ignored.
From http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options
Upvotes: 2