1

I'm currently working on getting a treegrid going where I'm overriding the data functions to call a thrift service to fill in the data. The idea is that I load only the parent nodes then when the node is expanded it will dynamically call the thrift service to fill in the data. I have run into some quirks with the way the treegrid is behaving when I try to load the children dynamically. It will load the initial list fine but when I go to dynamically load the child it's not adding it when the parent is expanded. Now if you expand the second entry it add the child to the list in the correct position but it doesn't see it as a child of 287.

I can't seem to grasp what I'm doing wrong with it that it doesn't want to properly add as a child.

// The data that is returned via thrift to fill in the initial entry in the table

{
"total" : "13″,
"page":"1″,
"records": "720″,
"rows" : [

{"id" : "287","cell" : ["287","MDXX00025",true,0,null,false,false] }
,{"id" : "544″,"isLeaf":true,"cell" : ["544","MDXX00460",true,0,null,false,false] }]
}

 // How jqGrid is configured with a oData object that contains the child I want to fill in.

var oData = { "rows" : [
{"id" : "7220","parent":287,"level":"1","isLeaf":true,"loaded":true,"empty":"MDXX00450" }]
};

function DoWork(postdata)
{
     var sData = client.NavigateTable(postdata._search,postdata.page,postdata.rows,postdata.sidx,

            postdata.sord,postdata.totalrows);
     var obj = jQuery.parseJSON(sData);
     var thegrid = jQuery("#addtree")[0];
     thegrid.addJSONData(obj);
}

function DoTreeWork(postdata)
{
     var thegrid = $("#addtree");
     thegrid.jqGrid ('addChildNode', oData.rows[0].id, oData.rows[0].parent, oData.rows[0]);
}

jQuery(document).ready(function(){

    $.jgrid.defaults = $.extend($.jgrid.defaults,{loadui:"enable"});
    jQuery("#addtree").jqGrid({
    datatype: function(postdata)
    {
        DoWork(postdata);
    },
    treedatatype: function (postdata)
    {
        DoTreeWork(postdata);
    },
    treeGrid: true,
    treeGridModel: 'adjacency',
       colNames:["id","empty","docno,"],
       colModel:[
        {name:'id',index:'id', width:20,key:true, editable:false},
        {name:'empty',index:'empty',width:10},
           {name:'docno',index:'docno', width:30, editable:true}
       ],
    pager : "#paddtree",
    treeGrid: true,
    ExpandColumn : 'name',
    editurl:'server.asp',
    viewrecords: true,
    autowidth: true,
    height:'400',
    rowNum:52,
    rowTotal:100,
    gridview: true,
    sortorder: "asc",
    sortname: 'id',
    caption: "Grid"
});
jQuery("#addtree").jqGrid('navGrid',"#paddtree",{edit:true,add:false,del:true,search:false});
});

I have also noted that the same data passed into addJSONData will not work with the addChildNode. I'm not sure if this is by design or just an oversight. This whole example functions fine if all the data (parents and children) is passed at once at the beginning to addJSONData. Any help would be appreciated.

JoshD
  • 141
  • 9

2 Answers2

0

I am having similar issue. when I drop a tree node, I add child nodes to it using AddChildNode. but it is not working properly. The relationship between parent(dropped row) and child ( added rows in ondrop event) is not working. As a workaround solution , you delete dropped rows and add parent and child nodes.

-1
var orgExpandNode = $.fn.jqGrid.expandNode, 
    orgCollapseNode = $.fn.jqGrid.collapseNode;

    $.jgrid.extend({
        expandNode : function(rc) {
            if(this.getNodeChildren(rc).length===0){
             $.ajax({     
                 url : "http://localhost:8080/xx/",

                 success : function(data) {                    
                 var    result = data;                   
                 for(var i=0;i<result.length;i++){                      
                           grid.addChildNode(result[i].id,result[i].parent,result[i]); 
                 }
                 result=[];
                   }
             });   
            }
          return orgExpandNode.call(this, rc);
        },
    });
Walery Strauch
  • 6,792
  • 8
  • 50
  • 57