if i add local data (one row) to an existing jqgrid, the autogenerated value by $.jgrid.randId()
seems to be wrong. I need the new row id for further actions.
var mydata = [
{id: '12', thingy: "abc"},
{id: '34', thingy:"def"},
{id: '56', thingy: 'ghi'}
];
$("#grid").jqGrid({
data: mydata ,
datatype: 'local',
gridview: true,
height: 'auto',
autoencode: true,
rowNum: 3,
colModel: [{
name: 'id',
width: 60,
},{
name: 'thingy',
width: 90,
}],
caption: "Stack Overflow Example",
ondblClickRow: function(rowid) {
console.log(rowid); // print current row id
}
});
$('#UpdateGridButton').click(function(){
var p = $('#grid').getGridParam();
console.log("found gridParamData:", p.data);
if (p.data){
var newData = [
{id: '78', thingy: "jkl"}
];
var rowId = $.jgrid.randId(); // new row ID
$("#grid").jqGrid('addRowData', rowId, newData);
console.log(rowId); // print new row id
}
});
See this fiddle & console output (2x click the row): http://jsfiddle.net/quK3s/
You see, if you add a new row, row id is "jqg1" but actually it inserts a row with "jqg2" (inspect with firebug, see console output if double clicking the row)
Any Ideas how to solve this issue? or is it a bug?
As i see in this question https://stackoverflow.com/a/9218310/2221820, i think the function is wrong and it should be pre-increment instead of $.jgrid.guid++
.
Any thoughts?
UPDATE:
i ended up with using
var rowId = $.jgrid.uidPref + (++$.jgrid.guid);
but any better solution/idea would be appreciated.