I have this code:
$(grid).jqGrid('addRowData', 'foo', d);
$(grid).jqGrid('addRowData', 'bar', 'baz');
As viewed in FireBug, it creates this DOM:
<tr id="undefined" class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" role="row">
<tr id="bar" class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" role="row">
The data expressed in 'd' matches the column model and it displays correctly (so I know the grid basically works fine). BUT, the 'id' on the first row is not set. On the other hand, 'baz' is garbage; this creates a blank row, BUT, the 'id' is correctly set to 'bar'.
In both cases I am sure the ID's are unique within my DOM, plus, I have observed that using non-unique ID's does not cause any immediate problems.
SO; I can't see开发者_高级运维 why the id on the first row is not set. Any ideas?
Try this:-
$(grid).jqGrid('addRowData', 'foo', 'd');
$(grid).jqGrid('addRowData', 'bar', 'baz');
data should be in quote otherwise you can declare the variable
like
var d='sample';
$(grid).jqGrid('addRowData', 'foo', d);
$(grid).jqGrid('addRowData', 'bar', 'baz');
Suppose d is an array check d and d[0] if d[0] have a value then go with d[0] :-
$(grid).jqGrid('addRowData', 'foo', d[0]);
(or)
$(grid).jqGrid('addRowData', 'foo', d[id]);
it will be work fine...
精彩评论