(Ext.net1.0)ColumnTree使用过程

 效果图:

(Ext.net1.0)ColumnTree使用过程_第1张图片

 

JS,refreshTree是为了在需要的时候重新刷新树:

  var refreshTree = function (tree) {
            Ext.net.DirectMethods.RefreshTree({
                success: function (result) {
                    var nodes = eval(result);
                    if (nodes.length > 0) {
                        tree.initChildren(nodes);
                    }
                    else {
                        tree.getRootNode().removeChildren();
                    }
                }
            });
        }

 

aspx:

 <ext:ColumnTree ID="BudgetDetailTree" ActiveEditor="Editor2" runat="server" 
                        Region="Center" Layout="Fit" Title="项目费用对比明细" Height="300" RootVisible="false"
                        AutoScroll="true">
                        <Columns>
                            <ext:ColumnTreeColumn Header="科目" Width="330" DataIndex="SubjectName" />
                            <ext:ColumnTreeColumn Header="预算值(元)" Width="100" DataIndex="BudgetValue" />
                            <ext:ColumnTreeColumn Header="已发生值(元)" Width="100" DataIndex="RealValue" />
                            <ext:ColumnTreeColumn Header="偏差(元)" Width="100" DataIndex="DeviationValue" />
                        </Columns>
                        <Loader>
                            <ext:TreeLoader>
                                <UIProviders>
                                    <ext:TreeNodeUIProvider Alias="col" ClassName="<%# ColumnTree.ColumnNodeUI %>" AutoDataBind="true" />
                                </UIProviders>
                            </ext:TreeLoader>
                        </Loader>
                        <Root>
                        </Root>
                    </ext:ColumnTree>


相关CS代码:

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                
                BindBudgetDetailTree(BudgetDetailTree.Root);    
            }
        }

               [DirectMethod]
        public string RefreshTree()
        {
            Ext.Net.TreeNodeCollection nodes = this.BindBudgetDetailTree(null);

            return nodes.ToJson();
        }


        /// <summary>
        /// 项目预算根级科目ID
        /// </summary>
        private static int m_budgetRootSubjectId = int.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["BudetSubjectRootId"]);
        protected Ext.Net.TreeNodeCollection BindBudgetDetailTree(Ext.Net.TreeNodeCollection nodes)
        {
            if (nodes == null)
            {
                nodes = new Ext.Net.TreeNodeCollection();
            }

            IList<BudgetSubject> rootNodes = ((BudgetSubjectBLL)BusinessManager).GetChildBudgetSubjects(int.Parse(CurProjectId), m_budgetRootSubjectId);
            Ext.Net.TreeNode rootNode = new Ext.Net.TreeNode();
            rootNode.Expanded = true;            
            nodes.Add(rootNode);
            BindTreeNodes(rootNode.Nodes, rootNodes);

            return nodes;
        }

        private void BindTreeNodes(Ext.Net.TreeNodeCollection nodes,IList<BudgetSubject> nodeDatas)
        {
            if (nodeDatas != null)
            {
                foreach (var n in nodeDatas)
                {
                    Ext.Net.TreeNode node = BuildTreeNode(n);
                    nodes.Add(node);
                    //IsLeaf 为0时表示还有子科目,继续加载子科目
                    if (n.Subject.IsLeaf.Value == 0)
                    {
                        IList<BudgetSubject> childNodeDatas = ((BudgetSubjectBLL)BusinessManager).GetChildBudgetSubjects(int.Parse(CurProjectId), n.SubjectId.Value);
                        if (childNodeDatas != null)
                        {
                            BindTreeNodes(node.Nodes, childNodeDatas);
                        }
                    }
                }
            }
        }

        private Ext.Net.TreeNode BuildTreeNode(BudgetSubject data)
        {
            Ext.Net.TreeNode node = new Ext.Net.TreeNode();
            node.UIProvider = "col";           
            node.Expanded = true;
            node.CustomAttributes.Add(new ConfigItem("SubjectName", data.SubjectName, ParameterMode.Value));
            node.CustomAttributes.Add(new ConfigItem("BudgetValue", data.BudgetValue.ToString(), ParameterMode.Value));          
            node.CustomAttributes.Add(new ConfigItem("RealValue", data.RealValue.ToString(), ParameterMode.Value));
            if (data.BudgetInfo.IsVerify)
            {
                var deviationVal = decimal.Subtract(data.BudgetValue.Value, data.VerifyValue.Value);
                node.CustomAttributes.Add(new ConfigItem("DeviationValue", deviationVal.ToString(), ParameterMode.Value));
            }
            else
            {
                node.CustomAttributes.Add(new ConfigItem("DeviationValue", "------", ParameterMode.Value));
            }

            if (data.Subject.ParentId == m_budgetRootSubjectId)
            {
                node.Icon = Icon.FolderGo;
                m_alreadyHappenedAmount = decimal.Add(m_alreadyHappenedAmount, data.RealValue.Value);
            }
            else
                node.Icon = Icon.Cog;          
        
            return node;
        }


 


 

你可能感兴趣的:(function,object,header,ext,layout,null)