Trying to us the jqgrid as a tree, prefer to add nodes manually, something like the code below. I have tried using the addChildNode method with no luck. I know the docs say 'Currently jqGrid can work only with data returned from server.', but the 4.0.0 changes "Added method addChildNode". I am using custom async (jQuery ajax) calls to retrieve data from the server, upon callback I would like to just add the appropriate nodes to the tree. Also the parameters to addChildNode are defined as: nodeid, parentid, data, but the data parameter also contains nodeid, parentid – ?
$("#tree1″).jqGrid({
datatype: function (treePostData) { treeLoad(treePostData); },
colNames: ["id", "name"],
colModel: [
{ name: 'id', index: 'id', width: 1, hidden: true, key: true },
{ name: 'name', index: 'name', width: 180 }
],
height: '100%',
rowNum: 10000,
sortname: 'id',
treeGrid: true,
treeGridModel: 'adjacency',
treedatatype: function (treePostData) { treeLoad(treePostData); },
ExpandColumn: 'name',
caption: "Tree Grid"
});
function treeLoad(treePostData){
//add nodes to the grid
//not working… nodeid, parentid, data
//the following line throws a javascript error in jquery-1.6.1, line 998: 'undefined' is null or not an object
$("#tree1″).jqGrid("addChildNode", "1″, null, { id: "1″, name: "xyz1″, level: 0, parent: null, isLeaf: false, expanded:false });
}