[Ext.Net]TreePanel+gridPanel实例


@小花要完整例子,尝试一下图文并茂,力求完整。

gridPanel TreePanel.JPG (27.49 KB, 下载次数: 16)

下载附件  保存到相册

2013-1-6 11:24 上传


前台代码
  1. <ext:ResourceManager ID="ResourceManager1" DirectMethodNamespace="RM" runat="server" />
  2. <ext:Store ID="StoreDeptDetailList" OnBeforeStoreChanged="StoreChanged" runat="server">
  3. <Reader>
  4. <ext:JsonReader IDProperty="ID">
  5. <Fields>
  6. <ext:RecordField Name="ID" />
  7. <ext:RecordField Name="wzdm" />
  8. ... ....
  9. <ext:RecordField Name="bz" />
  10. </Fields>
  11. </ext:JsonReader>
  12. </Reader>
  13. </ext:Store>
  14. <ext:Viewport ID="Viewport1" runat="server" Layout="border">
  15. <Items>
  16. <ext:Panel ID="Panel1" runat="server" Region="West" Split="true" Width="225" Border="false"
  17. AutoScroll="true">
  18. <Content>
  19. <ext:TreePanel ID="treePanel" runat="server" Border="false">
  20. <Root>
  21. </Root>
  22. <Listeners>
  23. <Click Handler="e.stopEvent();RM.NodeClick(node.id);" />
  24. </Listeners>
  25. </ext:TreePanel>
  26. </Content>
  27. </ext:Panel>
  28. <ext:Panel ID="PanelCenter" runat="server" Region="Center" Layout="Fit" Cls="ViewPortRight"
  29. ButtonAlign="Right" Width="270" Header="false" Title="物资明细" Icon="TableGear"
  30. Border="false">
  31. <Items>
  32. <ext:GridPanel ID="gpFuncsList" runat="server" StripeRows="true" ClicksToEdit="0"
  33. Header="false" Height="600" StoreID="StoreDeptDetailList" Border="true" TrackMouseOver="true">
  34. <TopBar>
  35. <ext:Toolbar ID="Toolbar2" runat="server" AutoWidth="true">
  36. <Items>
  37. <ext:Label runat="server" ID="lblTitle">
  38. </ext:Label>
  39. <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
  40. <ext:Button ID="btnAdd" runat="server" Text="新增" Icon="Add">
  41. <Listeners>
  42. <Click Handler="#{gpFuncsList}.insertRecord();" />
  43. </Listeners>
  44. </ext:Button>
  45. <ext:Button ID="btnDelete" runat="server" Text="删除" Icon="Delete">
  46. <Listeners>
  47. <Click Handler="#{gpFuncsList}.deleteSelected();" />
  48. </Listeners>
  49. </ext:Button>
  50. <ext:Button ID="btnSave" runat="server" Text="保存" Icon="Disk">
  51. <Listeners>
  52. <Click Handler="#{gpFuncsList}.save();" />
  53. </Listeners>
  54. </ext:Button>
  55. </Items>
  56. </ext:Toolbar>
  57. </TopBar>
  58. <ColumnModel ID="ColumnModel1" runat="server">
  59. <Columns>
  60. <ext:Column ColumnID="wzmc" DataIndex="wzmc" Header="物资名称" Align="Center" Sortable="false">
  61. <Editor>
  62. <ext:TextField ID="TextField1" runat="server" />
  63. </Editor>
  64. </ext:Column>
  65. <ext:Column ColumnID="ggxh" DataIndex="ggxh" Header="规格型号" Align="Center" Sortable="false">
  66. <Editor>
  67. <ext:TextField ID="TextField2" runat="server" />
  68. </Editor>
  69. </ext:Column>
  70. <ext:Column ColumnID="bcdd" DataIndex="bcdd" Header="保存地点" Align="Center" Sortable="false">
  71. <Editor>
  72. <ext:TextField ID="TextField3" runat="server" />
  73. </Editor>
  74. </ext:Column>
  75. <ext:Column ColumnID="sccj" DataIndex="sccj" Header="生产厂家" Align="Center" Sortable="false">
  76. <Editor>
  77. <ext:TextField ID="TextField4" runat="server" />
  78. </Editor>
  79. </ext:Column>
  80. <ext:Column ColumnID="jxs" DataIndex="jxs" Header="经销商" Align="Center" Sortable="false">
  81. <Editor>
  82. <ext:TextField ID="TextField5" runat="server" />
  83. </Editor>
  84. </ext:Column>
  85. <ext:Column ColumnID="zzs" DataIndex="zzs" Header="制造商" Align="Center" Sortable="false">
  86. <Editor>
  87. <ext:TextField ID="TextField6" runat="server" />
  88. </Editor>
  89. </ext:Column>
  90. <ext:Column ColumnID="isny" DataIndex="isny" Header="是否为耐用品" Align="Center" Sortable="false">
  91. <Editor>
  92. <ext:ComboBox ID="TextField7" runat="server">
  93. <Items>
  94. <ext:ListItem Text="是" Value="是" />
  95. <ext:ListItem Text="否" Value="否" />
  96. </Items>
  97. </ext:ComboBox>
  98. </Editor>
  99. </ext:Column>
  100. <ext:Column ColumnID="jldw" DataIndex="jldw" Header="计量单位" Align="Center" Sortable="false">
  101. <Editor>
  102. <ext:ComboBox ID="ComboBox4" runat="server">
  103. <Items>
  104. <ext:ListItem Text="方" Value="方" />
  105. <ext:ListItem Text="公斤" Value="公斤" />
  106. <ext:ListItem Text="发" Value="发" />
  107. <ext:ListItem Text="根" Value="根" />
  108. <ext:ListItem Text="台" Value="台" />
  109. <ext:ListItem Text="灯" Value="灯" />
  110. <ext:ListItem Text="吨" Value="顿" />
  111. <ext:ListItem Text="米" Value="米" />
  112. <ext:ListItem Text="鞋" Value="鞋" />
  113. <ext:ListItem Text="套" Value="套" />
  114. <ext:ListItem Text="块" Value="块" />
  115. <ext:ListItem Text="辆" Value="辆" />
  116. <ext:ListItem Text="个" Value="个" />
  117. <ext:ListItem Text="把" Value="把" />
  118. </Items>
  119. </ext:ComboBox>
  120. </Editor>
  121. </ext:Column>
  122. <ext:Column ColumnID="cph" DataIndex="cph" Header="车牌号" Align="Center" Sortable="false">
  123. <Editor>
  124. <ext:TextField ID="TextField12" runat="server" />
  125. </Editor>
  126. </ext:Column>
  127. <ext:Column ColumnID="djgl" DataIndex="djgl" Header="电机功率" Sortable="false">
  128. <Editor>
  129. <ext:TextField ID="TextField13" runat="server" />
  130. </Editor>
  131. </ext:Column>
  132. <ext:Column ColumnID="zjs" DataIndex="jzs" Header="间(座)数" Align="Center" Sortable="false">
  133. <Editor>
  134. <ext:NumberField ID="TextField14" runat="server" />
  135. </Editor>
  136. </ext:Column>
  137. <ext:Column ColumnID="nx" DataIndex="nx" Header="使用年限" Align="Center" Sortable="false">
  138. <Editor>
  139. <ext:SpinnerField ID="SpinnerField2" runat="server" MinValue="1" MaxValue="100" AllowDecimals="true"
  140. DecimalPrecision="1" Accelerate="true" />
  141. </Editor>
  142. </ext:Column>
  143. <ext:Column ColumnID="scrq" DataIndex="scrq" Header="生产日期" Align="Center" Sortable="false">
  144. <Editor>
  145. <ext:DateField ID="TextField9" runat="server" />
  146. </Editor>
  147. <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d')" />
  148. </ext:Column>
  149. <ext:Column ColumnID="dqr" DataIndex="dqr" Header="到期日" Align="Center" Sortable="false">
  150. <Editor>
  151. <ext:DateField ID="TextField10" runat="server" />
  152. </Editor>
  153. <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d')" />
  154. </ext:Column>
  155. <ext:Column ColumnID="bz" DataIndex="bz" Header="备注" Align="Center" Sortable="false">
  156. <Editor>
  157. <ext:TextField ID="TextField11" runat="server" />
  158. </Editor>
  159. </ext:Column>
  160. </Columns>
  161. </ColumnModel>
  162. <BottomBar>
  163. <ext:PagingToolbar runat="server" ID="PagingToolbar1" PageSize="20" StoreID="StoreDeptDetailList">
  164. </ext:PagingToolbar>
  165. </BottomBar>
  166. <SelectionModel>
  167. <ext:RowSelectionModel ID="RowSelectionModel1" runat="server">
  168. </ext:RowSelectionModel>
  169. </SelectionModel>
  170. <LoadMask ShowMask="true" />
  171. </ext:GridPanel>
  172. </Items>
  173. </ext:Panel>
  174. </Items>
  175. </ext:Viewport>
复制代码
后台代码
  1. DataTable dt = new DataTable();
  2. protected void Page_Load(object sender, EventArgs e)
  3. {
  4. if (!IsPostBack && !X.IsAjaxRequest)
  5. {
  6. BuildTree(this.treePanel.Root);

  7. Hidden();
  8. }
  9. }

  10. #region 创建树
  11. //添加节点
  12. private Ext.Net.TreeNodeCollection BuildTree(Ext.Net.TreeNodeCollection nodes)
  13. {
  14. try
  15. {
  16. if (nodes == null)
  17. {
  18. nodes = new Ext.Net.TreeNodeCollection();
  19. }
  20. dt = wzflBLL.Instance.getALlwzml();

  21. DataRow[] drx = dt.Select(" FatherCode=''");

  22. Ext.Net.TreeNode root = new Ext.Net.TreeNode();
  23. root.NodeID = drx[0]["wzdm"].ToString();
  24. root.Text = drx[0]["wzmc"].ToString();
  25. root.Qtip = drx[0]["wzmc"].ToString();
  26. root.Expanded = true;
  27. root.Draggable = false;
  28. root.HrefTarget = drx[0]["wzdm"].ToString();
  29. nodes.Add(root);
  30. //添加相应子节点
  31. this.AddNodes(root);
  32. //ResourceManager1.AddScript("RefreshTree();");
  33. return nodes;
  34. }
  35. catch (Exception ex)
  36. {
  37. throw ex;
  38. }
  39. }

  40. //添加子节点
  41. private void AddNodes(Ext.Net.TreeNode parent)
  42. {
  43. DataRow[] drx = dt.Select();
  44. drx = dt.Select("FatherCode='" + parent.NodeID + "'");
  45. if (drx.Length == 0)
  46. {
  47. return;
  48. }
  49. foreach (DataRow dr in drx)
  50. {
  51. Ext.Net.TreeNode node = new Ext.Net.TreeNode();
  52. node.NodeID = dr["wzdm"].ToString();
  53. node.Text = dr["wzmc"].ToString();
  54. node.Qtip = dr["wzmc"].ToString();
  55. node.HrefTarget = dr["wzdm"].ToString();
  56. parent.Nodes.Add(node);
  57. AddNodes(node);
  58. }
  59. }
  60. #endregion

  61. //NODE点击事件
  62. [DirectMethod]
  63. public void NodeClick(string nodeID)
  64. {

  65. hdPid.Text = nodeID;
  66. String wzdm = "";
  67. //根据选中的树节点 来动态隐藏列
  68. if (hdPid.Text != "")
  69. {
  70. wzdm = wzmxBLL.getMaxFahterCode(hdPid.Text);
  71. }
  72. if (wzdm == "3")
  73. {
  74. gpFuncsList.ColumnModel.SetHidden(8, false);
  75. gpFuncsList.ColumnModel.SetHidden(9, false);
  76. gpFuncsList.ColumnModel.SetHidden(10, false);
  77. gpFuncsList.ColumnModel.SetHidden(6, true);
  78. }
  79. else if (wzdm == "2")
  80. {
  81. gpFuncsList.ColumnModel.SetHidden(6, false);
  82. gpFuncsList.ColumnModel.SetHidden(8, true);
  83. gpFuncsList.ColumnModel.SetHidden(9, true);
  84. gpFuncsList.ColumnModel.SetHidden(10, true);
  85. }
  86. else
  87. {
  88. gpFuncsList.ColumnModel.SetHidden(6, true);
  89. gpFuncsList.ColumnModel.SetHidden(8, true);
  90. gpFuncsList.ColumnModel.SetHidden(9, true);
  91. gpFuncsList.ColumnModel.SetHidden(10, true);

  92. }
  93. List<wzmxEntity> list = wzmxBLL.Instance.GetEntities(" where 1=1 and fldm='" + nodeID + "'");

  94. StoreDeptDetailList.DataSource = list;
  95. StoreDeptDetailList.DataBind();
  96. }

  97. protected void Hidden()
  98. {
  99. gpFuncsList.ColumnModel.SetHidden(6, true);
  100. gpFuncsList.ColumnModel.SetHidden(8, true);
  101. gpFuncsList.ColumnModel.SetHidden(9, true);
  102. gpFuncsList.ColumnModel.SetHidden(10, true);
  103. }

  104. protected void StoreChanged(object sender, BeforeStoreChangedEventArgs e)
  105. {
  106. ChangeRecords<wzmxEntity> persons = e.DataHandler.ObjectData<wzmxEntity>();
  107. foreach (wzmxEntity created in persons.Created)
  108. {
  109. wzmxEntity entity = created;
  110. entity.dwdm = Request.Cookies["danwei"].Value.Trim();
  111. entity.bmdm = Request.Cookies["bumen"].Value.Trim();
  112. entity.fldm = hdPid.Text;
  113. entity.wzdm = wzrkmlDal.GetNumber("008", "");
  114. wzmxBLL.Instance.Insert(ref entity);
  115. }
  116. foreach (wzmxEntity updated in persons.Updated)
  117. {
  118. wzmxBLL.Instance.Update(updated);
  119. }
  120. e.Cancel = true;

  121. }
  122. }

http://www.ext.net.cn/forum.php?mod=viewthread&tid=1498&extra=page%3D4

你可能感兴趣的:([Ext.Net]TreePanel+gridPanel实例)