Ext.ux.tree.treegrid异步加载数据

///前台
var grid = new Ext.ux.tree.TreeGrid({
        title: '任务管理',
        width: 500,
        height: 300,
        enableDD: true,
        enableSort:false,  
        rootVisible:false,  
        columns:[{
            header: '任务名称',
            dataIndex: 'Task_ID',
            width: 230
        },{
            header: '开始时间',
            width: 100,
            dataIndex: 'TaskName',
            align: 'center'
        }],
        root:new Ext.tree.AsyncTreeNode({
            id:'0',
            loader:new Ext.tree.TreeLoader({
                 dataUrl: 'Data/Work_Task/Work_Task.aspx?flag=0',
                 listeners:{
                     "beforeload":function(treeloader,node)
                     {
                        treeloader.baseParams={
                        treegrid_id:node.id,
                        method:'POST'
                        };
                     }
                 }  
            })
        }),
        listeners:
        {
            "click":function(node,event)
            {
                if (node.isLeaf()) {
			        event.stopEvent();
		        } else {
				    event.stopEvent();
				    node.toggle();
		        }
            }
        }
      
    });
//后台返回值的方法
 public string GetData_TaskInfo(string _id)
        {
            if (_id == "0") //第一次加载,只加载父节点
            {
                string _fathers = "";
                DataSet dsWorkInfo = TIS.Get_TaskInfo(_id, "");

                foreach (DataRow r_Work in dsWorkInfo.Tables[0].Rows)
                {
                    _fathers += "{leaf: false,id:'" + r_Work[0] + "',";
                    foreach (DataColumn column_Work in dsWorkInfo.Tables[0].Columns)
                    {
                        _fathers += column_Work.ColumnName + ":'" + r_Work[column_Work].ToString() + "',";
                    }
                    _fathers = _fathers.Remove(_fathers.Length - 1, 1);
                    _fathers += "},";
                }
                if (_fathers == "")
                {
                    return "";
                }
                return _fathers = " [" + _fathers.Remove(_fathers.Length - 1, 1) + "]";
            }
            else //第二次加载,加载子节点
            {
                string _fathers = "";
                DataSet dsStageTaskInfo = TIS.Get_StageTask(_id);

                foreach (DataRow r_StageTask in dsStageTaskInfo.Tables[0].Rows)
                {
                    _fathers += "{leaf: true,";
                    foreach (DataColumn column_StageTask in dsStageTaskInfo.Tables[0].Columns)
                    {
                        _fathers += column_StageTask.ColumnName + ":'" + r_StageTask[column_StageTask].ToString() + "',";
                    }
                    _fathers = _fathers.Remove(_fathers.Length - 1, 1);
                    _fathers += "},";
                }
                if (_fathers == "")
                {
                    return "";
                }
                return _fathers = " [" + _fathers.Remove(_fathers.Length - 1, 1) + "]";
            }
        }

相关推荐