public void BuildLevel(int level, string recId, string gridId) { var storeId = "L".ConcatWith(level, "_", recId, "_Store"); var newGridId = "L".ConcatWith(level, "_", recId, "_Grid"); // build store var store = new Store { ID = storeId }; var reader = new JsonReader { IDProperty = "ID" }; reader.Fields.Add("ID", "Name"); reader.Fields.Add(new RecordField { Name = "Level", Convert = { Handler = "return ".ConcatWith(level, ";") } }); store.Reader.Add(reader); store.CustomConfig.Add(new ConfigItem("level", level.ToString(), ParameterMode.Raw)); // bind store var data = new List <object>(); for (int i = 1; i <= 9; i++) { data.Add(new { ID = recId.ConcatWith("_R", i), Name = "Level".ConcatWith(level, ": Row " + i) }); } //build grid var grid = new GridPanel { ID = newGridId, Store = { store }, AutoHeight = true, EnableColumnMove = level == 1 }; //build columns grid.ColumnModel.Columns.Add(new RowNumbererColumn { Width = 25 }); if (level == 1) { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Name" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Class" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Class1" }); } else { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Name", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Class", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Class1", Resizable = false }); } grid.ColumnModel.ID = newGridId + "_CM"; // build view var view = new Ext.Net.GridView { ID = newGridId + "_View", ForceFit = true }; grid.View.Add(view); // build selection model var sm = new RowSelectionModel { ID = newGridId + "_SM" }; if (level != 3) { sm.Listeners.BeforeRowSelect.Handler = "return false;";//合计类不允许选择 } grid.SelectionModel.Add(sm); // add expander for all levels except last (last level is 5) if (level < 3) { view.Listeners.BeforeRefresh.Fn = "clean"; var re = new RowExpander { ID = newGridId + "_RE", EnableCaching = true, Template = { ID = newGridId + "_TPL", Html = "<div id=\"row_{ID}\" style=\"background-color:white;\"></div>" } }; re.Listeners.BeforeExpand.Fn = "loadLevel"; grid.Plugins.Add(re); } store.DataSource = data; store.DataBind(); if (level == 1) { grid.Title = "MultiLevel grid"; grid.Width = 600; grid.Height = 600; grid.AutoHeight = false; //this.Form.Controls.Add(grid); Container1.Items.Add(grid); grid.Plugins.Add(new PanelResizer()); } else { var renderEl = "row_" + recId; X.Get(renderEl).SwallowEvent(new string[] { "click", "mousedown", "mouseup", "dblclick" }, true); this.RemoveFromCache(newGridId, gridId); grid.Render(renderEl, RenderMode.RenderTo); this.AddToCache(newGridId, gridId); } }
public void BuildLevel(int level, string recId, string gridId, string dtype) { var storeId = "L".ConcatWith(level, "_", recId, "_Store"); var newGridId = "L".ConcatWith(level, "_", recId, "_Grid"); // build store var store = new Store { ID = storeId }; var reader = new JsonReader { IDProperty = "ID" }; reader.Fields.Add("ID", "Type", "Heji", "Biaodanhao", "Tijiao"); reader.Fields.Add(new RecordField { Name = "Level", Convert = { Handler = "return ".ConcatWith(level, ";") } }); store.Reader.Add(reader); //store.CustomConfig.Add(new ConfigItem("level", level.ToString(), ParameterMode.Raw)); // bind store DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Type"); dt.Columns.Add("Heji"); dt.Columns.Add("Biaodanhao"); dt.Columns.Add("Tijiao"); if (level == 1) { DataRow dr = dt.NewRow(); dr["ID"] = "0"; dr["Type"] = "差旅费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS110" + level.ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = "1"; dr["Type"] = "通用费用"; dr["Heji"] = "1100"; dr["Biaodanhao"] = "BJS111" + level.ToString(); dr["Tijiao"] = "2012-12-21"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = "2"; dr["Type"] = "差旅费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS112" + level.ToString(); dr["Tijiao"] = "2012-12-31"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = "3"; dr["Type"] = "通用费用"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS113" + level.ToString(); dr["Tijiao"] = "2012-11-11"; dt.Rows.Add(dr); } else if (level == 2) { if (dtype == "差旅费") { Random ran = new Random(); DataRow dr = dt.NewRow(); dr["ID"] = recId + "0"; dr["Type"] = "票价合计"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "1"; dr["Type"] = "酒店"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "2"; dr["Type"] = "交通费"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "3"; dr["Type"] = "膳食费"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "4"; dr["Type"] = "机场费"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "5"; dr["Type"] = "其他"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "6"; dr["Type"] = "每日津贴"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); } else { DataRow dr = dt.NewRow(); dr = dt.NewRow(); dr["ID"] = recId + "0"; dr["Type"] = "交际费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS110" + level.ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "1"; dr["Type"] = "交通费"; dr["Heji"] = "1100"; dr["Biaodanhao"] = "BJS111" + level.ToString(); dr["Tijiao"] = "2012-12-21"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "2"; dr["Type"] = "通讯费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS112" + level.ToString(); dr["Tijiao"] = "2012-12-31"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "3"; dr["Type"] = "其他费用"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS113" + level.ToString(); dr["Tijiao"] = "2012-11-11"; dt.Rows.Add(dr); } } else if (level == 3 && dtype != "差旅费") { for (int i = 0; i < 4; i++) { DataRow dr = dt.NewRow(); dr["ID"] = recId + i.ToString(); dr["Type"] = "其他费用"; dr["Heji"] = (100 + i).ToString(); dr["Biaodanhao"] = "费用描述"; dr["Tijiao"] = "2012-11-11"; dt.Rows.Add(dr); } } //var data = new List<object>(); //for (int i = 1; i <= 9; i++) //{ // data.Add(new { ID = recId.ConcatWith("_R", i), Biaodanhao = "Level".ConcatWith(level, ": Row " + i), Type = "Level".ConcatWith(level, ": Row " + i), Heji = "Level".ConcatWith(level, ": Row " + i), Tijiao = "Level".ConcatWith(level, ": Row " + i) }); //} //build grid var grid = new GridPanel { ID = newGridId, Store = { store }, AutoHeight = true, EnableColumnMove = level == 1 }; //build columns grid.ColumnModel.Columns.Add(new RowNumbererColumn { Width = 25 }); if (level == 1) { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Biaodanhao", Header = "表单号" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Type", Header = "单据类型" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "合计" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Tijiao", Header = "提交时间" }); } else if (level == 2) { if (dtype == "差旅费") { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Type", Header = "费用类型", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "合计", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Biaodanhao", Header = "公司预支", Resizable = false }); } else { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Type", Header = "单据类型", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "合计", Resizable = false }); } } else if (level == 3) { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "金额", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "费用描述", Resizable = false }); } grid.ColumnModel.ID = newGridId + "_CM"; // build view var view = new Ext.Net.GridView { ID = newGridId + "_View", ForceFit = true }; grid.View.Add(view); // build selection model var sm = new RowSelectionModel { ID = newGridId + "_SM" }; if (level != 3 && dtype != "差旅费") { sm.Listeners.BeforeRowSelect.Handler = "return false;";//合计类不允许选择 } grid.SelectionModel.Add(sm); // add expander for all levels except last (last level is 5) if (level < 3 && dtype != "差旅费") { view.Listeners.BeforeRefresh.Fn = "clean"; var re = new RowExpander { ID = newGridId + "_RE", EnableCaching = true, Template = { ID = newGridId + "_TPL", Html = "<div id=\"row_{ID}\" style=\"background-color:white;\"></div>" } }; re.Listeners.BeforeExpand.Fn = "loadLevel"; grid.Plugins.Add(re); } store.DataSource = dt; store.DataBind(); if (level == 1) { grid.Title = "MultiLevel grid"; grid.Width = 600; grid.Height = 400; grid.AutoHeight = false; //this.Form.Controls.Add(grid); Container1.Items.Add(grid); grid.Plugins.Add(new PanelResizer()); } else { var renderEl = "row_" + recId; X.Get(renderEl).SwallowEvent(new string[] { "click", "mousedown", "mouseup", "dblclick" }, true); this.RemoveFromCache(newGridId, gridId); grid.Render(renderEl, RenderMode.RenderTo); this.AddToCache(newGridId, gridId); } string gl = newGridId + "_SM"; //记录选择行的空间名 if (level == 3 || (level == 2 && dtype == "差旅费")) { X.AddScript("var st=Hidden1.getValue();Hidden1.setValue(st+='" + gl + ",');"); X.AddScript("var st=TextField1.getValue();TextField1.setValue(st+='" + gl + ",');"); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); GridView item = View.FirstOrDefault(); if (item == null) { item = new GridView(); item.EnableTextSelection = true; this.View.Add(item); } item.ID = this.ID + "View"; item.LoadingText = "正在加载"; item.LoadMask = true; PagingToolbar toolbar = new PagingToolbar(); Ext.Net.Button btnAdd = null; Ext.Net.Button button2 = null; if (this.EnableAdd) { if (EditorConfig == null || EditorConfig.AddWindow == null) { throw new Exception("EditorConfig的属性有误"); } btnAdd = new Ext.Net.Button { Text = "添加" }; btnAdd.Handler = string.Format("App.editWindow.setWidth({0});App.editWindow.setHeight({1});App.editWindow.setTitle('{2}');App.editWindow.show();App.editWindow.loader.load({{url:'{3}'}})", EditorConfig.AddWindow.Width, EditorConfig.AddWindow.Height, EditorConfig.AddWindow.Title, EditorConfig.AddWindow.Url); toolbar.Items.Add(btnAdd); } if (this.EnableRemove) { button2 = new Ext.Net.Button { Text = "删除" }; button2.DirectEvents.Click.EventMask.Msg = "正在删除"; button2.DirectEvents.Click.EventMask.ShowMask = true; button2.DirectEvents.Click.Confirmation.ConfirmRequest = true; button2.DirectEvents.Click.Confirmation.Message = "确认删除?"; button2.DirectEvents.Click.Confirmation.Title = "提示"; Parameter parameters = new Parameter { Name = "ids", Value = "getSelectionIds()", Mode = ParameterMode.Raw }; button2.DirectEvents.Click.ExtraParams.Add(parameters); } if (this.EditorConfig != null) { if (this.EnableAdd) { btnAdd.DirectEvents.Click.ExtraParams.AddRange(this.EditorConfig.ExtraParams); btnAdd.DirectEvents.Click.ExtraParams.AddRange(this.EditorConfig.AddWindow.ExtraParams); } if (this.EnableRemove) { button2.DirectEvents.Click.ExtraParams.AddRange(this.EditorConfig.ExtraParams); button2.DirectEvents.Click.ExtraParams.AddRange(this.EditorConfig.AddWindow.ExtraParams); } } if (this.EnableAdd) { } if (this.EnableRemove) { button2.DirectClick += new ComponentDirectEvent.DirectEventHandler(this.btnRemove_DirectClick); toolbar.Items.Add(button2); } if (BottomBar.Count > 0) { toolbar.Items.AddRange(BottomBar[0].Items); BottomBar.Clear(); } this.BottomBar.Add(toolbar); this.SelectionModel.Add(new CheckboxSelectionModel()); this.InitModel(); this.InitGridCommand(); if (!Ext.Net.X.IsAjaxRequest) { this.AddScript("function getSelectionIds(){var sm=Ext.getCmp(\"" + this.ID + "\").getSelectionModel();var ids=Array();var selections=sm.getSelection();for(var i=0;i<selections.length;i++)ids.push(selections[i].data.Id);return ids.join(',');}"); } }
protected override void CreateChildControls() { Width = 500; Height = 300; StyleSpec = "float:left;margin-bottom:15px"; CreateToolbar(); CreateColumnModel(); GridView gridView = new GridView(); gridView.GetRowClass.Fn = "childrenEditorGetRowClass"; View.Add(gridView); ResourceManager.RegisterClientStyleBlock("ChildrenEditorGridPanelStyles", @" .childrenEditor-deleted-row { background: #F0AAB2; } .childrenEditor-new-row { background: #c8ffc8; }"); ResourceManager.RegisterClientScriptBlock("ChildrenEditorGridPanelScript", @" var childrenEditorGetRowClass = function (record) { if (record.newRecord) { return 'childrenEditor-new-row'; } if (record.removed) { return 'childrenEditor-deleted-row'; } } var childrenEditorRenderIcon = function(value, p, record) { return String.format('<img src=""{0}"" alt=""{1}"" />', value, record.data.Title); } var flagRemovedItems = function(gridPanel) { var selections = gridPanel.getSelectionModel().getSelections(); for (var i = 0; i < selections.length; i++) {{ selections[i].newRecord = false; selections[i].removed = true; }} gridPanel.getSelectionModel().clearSelections(); gridPanel.getView().refresh(); } var flagRemovedItem = function(gridPanel, index) { var record = gridPanel.getStore().getAt(index); record.newRecord = false; record.removed = true; gridPanel.getView().refresh(); } var childrenEditorPrepareCommandToolbar = function (grid, toolbar, rowIndex, record) { // Could return false to hide toolbar. var button1 = toolbar.items.get(0); var button2 = toolbar.items.get(1); if (record.removed) { button1.setDisabled(true); button1.setTooltip('Disabled'); button2.setDisabled(true); button2.setTooltip('Disabled'); } };"); base.CreateChildControls(); }
public void BuildGrid() { Ext.Net.GridView gridView; if (String.IsNullOrEmpty(this.columnExpand)) { gridView = new Ext.Net.GridView(); } else { gridView = new Ext.Net.GridView { Configs = { ForceFit = true } }; } if (ReadOnly == true) { foreach (LookupFormatData fmtData in this.dataTemplate) { fmtData.ReadOnly = ReadOnly; } } foreach (LookupFormatData fmtData in this.dataTemplate) { fmtData.ID = fmtData.ID != "" ? fmtData.ID : fmtData.FieldName; if (fmtData.EditControl != null) { Column colCbo = new Column { ID = String.Format("{0}ColID", fmtData.ID), DataIndex = fmtData.FieldName, Text = fmtData.FieldTitle, Width = fmtData.ColWidth, Hidden = fmtData.ColWidth == 0 }; if (String.Equals(fmtData.FieldName, this.columnExpand)) { colCbo.Flex = 1; } //Makeup for option string if (fmtData.IsRenderer) { string funcRenderer = fmtData.FnRenderer; Ext.Net.Renderer rd = new Renderer { Fn = SCOPE + "." + funcRenderer }; colCbo.Renderer = rd; } if (!fmtData.ReadOnly) { colCbo.Editor.Add(fmtData.EditControl); } this.ColumnModel.Columns.Add(colCbo); } else if (fmtData.EditControl == null) { switch (fmtData.Type) { case ModelFieldType.String: #region String Column colText = new Column { ID = String.Format("{0}ColID", fmtData.ID), DataIndex = fmtData.FieldName, Text = fmtData.FieldTitle, Width = fmtData.ColWidth, Hidden = fmtData.ColWidth == 0, Align = Alignment.Left }; if (String.Equals(fmtData.FieldName, this.columnExpand)) { colText.Flex = 1; } if (fmtData.IsRenderer) { string funcRenderer = fmtData.FnRenderer; Ext.Net.Renderer rd = new Renderer { Fn = SCOPE + "." + funcRenderer }; colText.Renderer = rd; } if (!fmtData.ReadOnly == true) { TextField textEditor = new TextField { SelectOnFocus = true, //AllowBlank = false, //BlankText = "Not blank", MsgTarget = MessageTarget.Side }; if (fmtData.MaxLength > 0) { textEditor.MaxLength = fmtData.MaxLength; textEditor.MaxLengthText = String.Format("Chiều dài tối đa là {0} kí tự", textEditor.MaxLength); } if (fmtData.AllowBlank == false) { textEditor.AllowBlank = false; textEditor.BlankText = String.Format("Trường bắt buộc nhập giá trị"); } colText.Editor.Add(textEditor); } this.ColumnModel.Columns.Add(colText); #endregion break; case ModelFieldType.Boolean: #region Boolean CheckColumn colBool = new CheckColumn { ID = String.Format("{0}ColID", fmtData.ID), DataIndex = fmtData.FieldName, Text = fmtData.FieldTitle, Width = fmtData.ColWidth, Hidden = fmtData.ColWidth == 0, Editable = false, Align = Alignment.Center }; if (String.Equals(fmtData.FieldName, this.columnExpand)) { colBool.Flex = 1; } if (!fmtData.ReadOnly == true) { colBool.Editable = true; //TextField cbEditor = new TextField { SelectOnFocus = true }; //Ext.Net.Checkbox cbEditor = new Checkbox { Cls = "x-grid-checkheader-editor" }; //colBool.Editor.Add(cbEditor); } this.ColumnModel.Columns.Add(colBool); #endregion break; case ModelFieldType.Date: #region Date DateColumn colDate = new DateColumn { ID = String.Format("{0}ColID", fmtData.ID), DataIndex = fmtData.FieldName, Text = fmtData.FieldTitle, Width = fmtData.ColWidth, Hidden = fmtData.ColWidth == 0, Format = "dd/MM/yyyy", Align = Alignment.Center }; if (String.Equals(fmtData.FieldName, this.columnExpand)) { colDate.Flex = 1; } if (!fmtData.ReadOnly == true) { DateField dateEditor = new DateField { ID = String.Format("{0}_{1}_dateEditor", this.ClientID, fmtData.FieldName), Format = "dd/MM/yyyy", Vtype = "daterange", SelectOnFocus = true }; colDate.Editor.Add(dateEditor); } // colDate.Renderer.Handler = @"if(value == 'Mon Jan 01 1 07:00:00 GMT+0700 (SE Asia Standard Time)') // {return null;} // else{return Ext.Date.format(value, 'd/m/Y');}"; this.ColumnModel.Columns.Add(colDate); #endregion break; case ModelFieldType.Float: #region Float NumberColumn colFloat = new NumberColumn { ID = String.Format("{0}ColID", fmtData.ID), DataIndex = fmtData.FieldName, Text = fmtData.FieldTitle, Width = fmtData.ColWidth, Hidden = fmtData.ColWidth == 0, Format = "0.00/i", Align = Alignment.Right, }; if (!String.IsNullOrEmpty(fmtData.Format)) { colFloat.Format = fmtData.Format; } if (String.Equals(fmtData.FieldName, this.columnExpand)) { colFloat.Flex = 1; } if (!fmtData.ReadOnly == true) { //phongdd-100 //TextField textEdit = new TextField { StyleSpec = "text-align:right;vertical-align:bottom", SelectOnFocus = true }; NumberField FloatEditInt = new NumberField { StyleSpec = "text-align:right;vertical-align:bottom", SelectOnFocus = true, MinValue = 0, AllowDecimals = true, DecimalPrecision = 3 }; //end phongdd-100 colFloat.Editor.Add(FloatEditInt); } this.ColumnModel.Columns.Add(colFloat); #endregion break; case ModelFieldType.Int: #region Number NumberColumn colNumber = new NumberColumn { ID = String.Format("{0}ColID", fmtData.ID), DataIndex = fmtData.FieldName, Text = fmtData.FieldTitle, Width = fmtData.ColWidth, Hidden = fmtData.ColWidth == 0, Align = Alignment.Right, }; if (!String.IsNullOrEmpty(fmtData.Format)) { colNumber.Format = fmtData.Format; } if (String.Equals(fmtData.FieldName, this.columnExpand)) { colNumber.Flex = 1; } //Bat buoc go dau phay if (!fmtData.ReadOnly == true) { //phongdd-100 //TextField textEditInt = new TextField { StyleSpec = "text-align:right;vertical-align:bottom", SelectOnFocus = true }; NumberField textEditInt = new NumberField { StyleSpec = "text-align:right;vertical-align:bottom", SelectOnFocus = true, MinValue = 0, AllowDecimals = true }; //end phongdd-100 colNumber.Editor.Add(textEditInt); } this.ColumnModel.Columns.Add(colNumber); #endregion break; default: #region auto Column colAuto = new Column { ID = String.Format("{0}ColID", fmtData.ID), DataIndex = fmtData.FieldName, Text = fmtData.FieldTitle, Width = fmtData.ColWidth, Hidden = fmtData.ColWidth == 0, Align = Alignment.Left }; if (String.Equals(fmtData.FieldName, this.columnExpand)) { colAuto.Flex = 1; } if (fmtData.ReadOnly == true) { TextField textEditAuto = new TextField { StyleSpec = "text-align:right;vertical-align:bottom", SelectOnFocus = true }; colAuto.Editor.Add(textEditAuto); } this.ColumnModel.Columns.Add(colAuto); #endregion break; } } } this.toolTip = new ToolTip { Delegate = ".x-grid3-cell", TrackMouse = true, }; this.Plugins.Add(new CellEditing { ClicksToEdit = 1 }); this.ToolTips.Add(toolTip); this.SelectionModel.Add(new CellSelectionModel { }); this.View.Add(gridView); }
protected void loadgrid2(object sender, DirectEventArgs e) { var store = new Store { ID = "Store1" }; var reader = new JsonReader { IDProperty = "ID" }; reader.Fields.Add("ID", "Type", "Heji", "Biaodanhao", "Tijiao"); reader.Fields.Add(new RecordField { Name = "Level", Convert = { Handler = "return ".ConcatWith(1, ";") } }); store.Reader.Add(reader); DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Type"); dt.Columns.Add("Heji"); dt.Columns.Add("Biaodanhao"); dt.Columns.Add("Tijiao"); DataRow dr = dt.NewRow(); dr["ID"] = "10"; dr["Type"] = "差旅费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS1101"; dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = "11"; dr["Type"] = "通用费用"; dr["Heji"] = "1100"; dr["Biaodanhao"] = "BJS1112"; dr["Tijiao"] = "2012-12-21"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = "12"; dr["Type"] = "差旅费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS1123"; dr["Tijiao"] = "2012-12-31"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = "13"; dr["Type"] = "通用费用"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS1134"; dr["Tijiao"] = "2012-11-11"; dt.Rows.Add(dr); var grid = new GridPanel { ID = "Grid1", Store = { store }, AutoScroll = true, Border = false, Title = "可按住Ctrl以多选,然后点击右侧"+"按钮向右侧添加数据.", Height = 530 }; //build columns grid.ColumnModel.Columns.Add(new RowNumbererColumn { Width = 25 }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Biaodanhao", Header = "表单号" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Type", Header = "单据类型" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "合计" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Tijiao", Header = "提交时间" }); grid.ColumnModel.ID = "Grid1_CM"; var view = new Ext.Net.GridView { ID = "Grid1_View", ForceFit = true }; grid.View.Add(view); var sm = new RowSelectionModel { ID = "Grid1_SM" }; //sm.Listeners.BeforeRowSelect.Handler = "return false;";//合计类不允许选择 grid.SelectionModel.Add(sm); // add expander for all levels except last (last level is 5) view.Listeners.BeforeRefresh.Fn = "clean"; var re = new RowExpander { ID = "Grid1_RE", EnableCaching = true, Template = { ID = "Grid1_TPL", Html = "<div id=\"row_{ID}\" style=\"background-color:white;\"></div>" } }; re.Listeners.BeforeExpand.Fn = "loadLevel"; grid.Plugins.Add(re); Panel5.Items.Add(grid); store.DataSource = dt; store.DataBind(); grid.Listeners.ViewReady.Fn = "expangrid"; grid.Listeners.ViewReady.Single = true; grid.Render(); //X.AddScript("expandallgrid();"); //re.ExpandAll(); //BuildLevel(int level, string recId, string gridId,string dtype) // //for (int i = 0; i < dt.Rows.Count; i++) //{ // if (dt.Rows[i]["Type"].ToString() == "差旅费") // { // var newgridid = "L2_" + dt.Rows[i]["ID"].ToString() + "_Grid"; // var store2 = new Store { ID = "L2_" + dt.Rows[i]["ID"].ToString() + "_Store" }; // var reader2 = new JsonReader { IDProperty = "ID" }; // reader.Fields.Add("ID", "Type", "Heji", "Biaodanhao", "Tijiao"); // reader.Fields.Add(new RecordField // { // Name = "Level", // Convert = { Handler = "return ".ConcatWith(2, ";") } // }); // store2.Reader.Add(reader2); // DataTable dt2 = new DataTable(); // dt2.Columns.Add("ID"); // dt2.Columns.Add("Type"); // dt2.Columns.Add("Heji"); // dt2.Columns.Add("Biaodanhao"); // dt2.Columns.Add("Tijiao"); // Random ran = new Random(); // DataRow dr2 = dt2.NewRow(); // dr2["ID"] = dt.Rows[i]["ID"].ToString() + "0"; // dr2["Type"] = "票价合计"; // dr2["Heji"] = "120"; // dr2["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); // dr2["Tijiao"] = "2012-12-11"; // dt2.Rows.Add(dr2); // dr2 = dt2.NewRow(); // dr2["ID"] = dt.Rows[i]["ID"].ToString() + "1"; // dr2["Type"] = "酒店"; // dr2["Heji"] = "120"; // dr2["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); // dr2["Tijiao"] = "2012-12-11"; // dt2.Rows.Add(dr2); // dr2 = dt2.NewRow(); // dr2["ID"] = dt.Rows[i]["ID"].ToString() + "2"; // dr2["Type"] = "交通费"; // dr2["Heji"] = "120"; // dr2["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); // dr2["Tijiao"] = "2012-12-11"; // dt2.Rows.Add(dr2); // dr2 = dt2.NewRow(); // dr2["ID"] = dt.Rows[i]["ID"].ToString() + "3"; // dr2["Type"] = "膳食费"; // dr2["Heji"] = "120"; // dr2["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); // dr2["Tijiao"] = "2012-12-11"; // dt2.Rows.Add(dr2); // dr2 = dt2.NewRow(); // dr2["ID"] = dt.Rows[i]["ID"].ToString() + "4"; // dr2["Type"] = "机场费"; // dr2["Heji"] = "120"; // dr2["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); // dr2["Tijiao"] = "2012-12-11"; // dt2.Rows.Add(dr2); // dr2 = dt2.NewRow(); // dr2["ID"] = dt.Rows[i]["ID"].ToString() + "5"; // dr2["Type"] = "其他"; // dr2["Heji"] = "120"; // dr2["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); // dr2["Tijiao"] = "2012-12-11"; // dt2.Rows.Add(dr2); // dr2 = dt2.NewRow(); // dr2["ID"] = dt.Rows[i]["ID"].ToString() + "6"; // dr2["Type"] = "每日津贴"; // dr2["Heji"] = "120"; // dr2["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); // dr2["Tijiao"] = "2012-12-11"; // dt2.Rows.Add(dr2); // var grid2 = new GridPanel // { // ID = newgridid, // Store = { // store2 // }, // AutoHeight = true, // AutoScroll = true, // EnableColumnMove = false, // }; // //build columns // grid2.ColumnModel.Columns.Add(new RowNumbererColumn { Width = 25 }); // grid2.ColumnModel.Columns.Add(new Column { DataIndex = "Type", Header = "费用类型", Resizable = false }); // grid2.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "合计", Resizable = false }); // grid2.ColumnModel.Columns.Add(new Column { DataIndex = "Biaodanhao", Header = "公司预支", Resizable = false }); // grid2.ColumnModel.ID = newgridid + "_CM"; // var view2 = new Ext.Net.GridView // { // ID = newgridid+"_View", // ForceFit = true // }; // grid2.View.Add(view2); // var sm2 = new RowSelectionModel { ID = newgridid+"_SM" }; // sm2.Listeners.BeforeRowSelect.Handler = "return false;";//合计类不允许选择 // grid2.SelectionModel.Add(sm2); // // add expander for all levels except last (last level is 5) // view2.Listeners.BeforeRefresh.Fn = "clean"; // var re2 = new RowExpander // { // ID = newgridid+"_RE", // EnableCaching = true, // Template = { ID = newgridid+"_TPL", Html = "<div id=\"row_{ID}\" style=\"background-color:white;\"></div>" } // }; // //re2.Listeners.BeforeExpand.Fn = "loadLevel"; // grid2.Plugins.Add(re2); // var renderEl2 = "row_" + dt.Rows[i]["ID"].ToString(); // X.Get(renderEl2).SwallowEvent(new string[] { "click", "mousedown", "mouseup", "dblclick" }, true); // this.RemoveFromCache(newgridid, "Grid1"); // store2.DataSource = dt2; // store2.DataBind(); // grid.Render(renderEl2, RenderMode.RenderTo); // this.AddToCache(newgridid, "Grid1"); // } //} //if (1 == 1) //{ // grid.Title = "可按住Ctrl以多选."; // grid.Height = 400; // grid.AutoHeight = false; // grid.Border = false; // //this.Form.Controls.Add(grid); // Panel5.Html = ""; // Panel5.Items.Add(grid); // //grid.Plugins.Add(new PanelResizer()); //} //else //{ //var renderEl = "row_" + recId; //X.Get(renderEl).SwallowEvent(new string[] { "click", "mousedown", "mouseup", "dblclick" }, true); //this.RemoveFromCache(newGridId, gridId); //grid.Render(renderEl, RenderMode.RenderTo); //this.AddToCache(newGridId, gridId); //} // }
public void BuildLevel(int level, string recId, string gridId,string dtype) { var storeId = "L".ConcatWith(level, "_", recId, "_Store"); var newGridId = "L".ConcatWith(level, "_", recId, "_Grid"); // build store var store = new Store { ID = storeId }; var reader = new JsonReader { IDProperty = "ID" }; reader.Fields.Add("ID", "Type", "Heji", "Biaodanhao", "Tijiao"); reader.Fields.Add(new RecordField { Name = "Level", Convert = { Handler = "return ".ConcatWith(level, ";") } }); store.Reader.Add(reader); //store.CustomConfig.Add(new ConfigItem("level", level.ToString(), ParameterMode.Raw)); // bind store DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Type"); dt.Columns.Add("Heji"); dt.Columns.Add("Biaodanhao"); dt.Columns.Add("Tijiao"); if (level == 1) { DataRow dr = dt.NewRow(); dr["ID"] = "0"; dr["Type"] = "差旅费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS110" + level.ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = "1"; dr["Type"] = "通用费用"; dr["Heji"] = "1100"; dr["Biaodanhao"] = "BJS111" + level.ToString(); dr["Tijiao"] = "2012-12-21"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = "2"; dr["Type"] = "差旅费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS112" + level.ToString(); dr["Tijiao"] = "2012-12-31"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = "3"; dr["Type"] = "通用费用"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS113" + level.ToString(); dr["Tijiao"] = "2012-11-11"; dt.Rows.Add(dr); } else if(level == 2) { if (dtype == "差旅费") { Random ran = new Random(); DataRow dr = dt.NewRow(); dr["ID"] = recId + "20"; dr["Type"] = "票价合计"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "21"; dr["Type"] = "酒店"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "22"; dr["Type"] = "交通费"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "23"; dr["Type"] = "膳食费"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "24"; dr["Type"] = "机场费"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "25"; dr["Type"] = "其他"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "26"; dr["Type"] = "每日津贴"; dr["Heji"] = "120"; dr["Biaodanhao"] = (120 * Math.Round((decimal)ran.Next(1, 10), 1)).ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); } else { DataRow dr = dt.NewRow(); dr = dt.NewRow(); dr["ID"] = recId + "20"; dr["Type"] = "交际费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS110" + level.ToString(); dr["Tijiao"] = "2012-12-11"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "21"; dr["Type"] = "交通费"; dr["Heji"] = "1100"; dr["Biaodanhao"] = "BJS111" + level.ToString(); dr["Tijiao"] = "2012-12-21"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "22"; dr["Type"] = "通讯费"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS112" + level.ToString(); dr["Tijiao"] = "2012-12-31"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ID"] = recId + "23"; dr["Type"] = "其他费用"; dr["Heji"] = "100"; dr["Biaodanhao"] = "BJS113" + level.ToString(); dr["Tijiao"] = "2012-11-11"; dt.Rows.Add(dr); } } else if (level == 3 && dtype != "差旅费") { for (int i = 0; i < 4; i++) { DataRow dr = dt.NewRow(); dr["ID"] = recId + "3" + i.ToString(); dr["Type"] = "其他费用"; dr["Heji"] = (100 + i).ToString(); dr["Biaodanhao"] = "费用描述"; dr["Tijiao"] = "2012-11-11"; dt.Rows.Add(dr); } } //var data = new List<object>(); //for (int i = 1; i <= 9; i++) //{ // data.Add(new { ID = recId.ConcatWith("_R", i), Biaodanhao = "Level".ConcatWith(level, ": Row " + i), Type = "Level".ConcatWith(level, ": Row " + i), Heji = "Level".ConcatWith(level, ": Row " + i), Tijiao = "Level".ConcatWith(level, ": Row " + i) }); //} //build grid var grid = new GridPanel { ID = newGridId, Store = { store }, AutoHeight = true, AutoScroll = true, EnableColumnMove = level == 1, }; //build columns grid.ColumnModel.Columns.Add(new RowNumbererColumn { Width = 25 }); if (level==1) { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Biaodanhao", Header = "表单号" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Type", Header = "单据类型" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "合计" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Tijiao", Header = "提交时间" }); } else if(level == 2) { if (dtype == "差旅费") { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Type", Header = "费用类型", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "合计", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Biaodanhao", Header = "公司预支", Resizable = false }); } else { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Type", Header = "单据类型", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "合计", Resizable = false }); } } else if (level == 3) { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "金额", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Heji", Header = "费用描述", Resizable = false }); } grid.ColumnModel.ID = newGridId + "_CM"; // build view var view = new Ext.Net.GridView { ID = newGridId + "_View", ForceFit = true }; grid.View.Add(view); // build selection model var sm = new RowSelectionModel { ID = newGridId + "_SM" }; //if (level != 3 && dtype != "差旅费") //{ // sm.Listeners.BeforeRowSelect.Handler = "return false;";//合计类不允许选择 //} grid.SelectionModel.Add(sm); RowExpander rem = new RowExpander(); // add expander for all levels except last (last level is 5) if (level < 3 && dtype != "差旅费") { view.Listeners.BeforeRefresh.Fn = "clean"; var re = new RowExpander { ID = newGridId + "_RE", EnableCaching = true, Template = { ID = newGridId + "_TPL", Html = "<div id=\"row_{ID}\" style=\"background-color:white;\"></div>" } }; re.Listeners.BeforeExpand.Fn = "loadLevel"; rem = re; grid.Plugins.Add(re); } store.DataSource = dt; store.DataBind(); if (level == 1) { grid.Title = "可按住Ctrl以多选."; grid.Height = 400; grid.AutoHeight = false; grid.Border = false; //this.Form.Controls.Add(grid); Panel5.Html = ""; Panel5.Items.Add(grid); //grid.Plugins.Add(new PanelResizer()); } else { var renderEl = "row_" + recId; X.Get(renderEl).SwallowEvent(new string[] { "click", "mousedown", "mouseup", "dblclick" }, true); this.RemoveFromCache(newGridId, gridId); if (level < 3) { grid.Listeners.ViewReady.Fn = "expangrid"; grid.Listeners.ViewReady.Single = true; } grid.Render(renderEl, RenderMode.RenderTo); this.AddToCache(newGridId, gridId); } //string gl = newGridId; ////记录选择行的空间名 //if (level == 3 || (level == 2 && dtype == "差旅费")) //{ // X.AddScript("var st=Hidden1.getValue();Hidden1.setValue(st+='" + gl + ",');"); // //X.AddScript("var st=TextField1.getValue();TextField1.setValue(st+='" + gl + ",');"); //} }
public void BuildLevel(int level, string recId, string gridId) { var storeId = "L".ConcatWith(level, "_", recId, "_Store"); var newGridId = "L".ConcatWith(level, "_", recId, "_Grid"); // build store var store = new Store { ID = storeId }; var reader = new JsonReader { IDProperty = "ID" }; reader.Fields.Add("ID", "Name"); reader.Fields.Add(new RecordField { Name = "Level", Convert = { Handler = "return ".ConcatWith(level, ";") } }); store.Reader.Add(reader); store.CustomConfig.Add(new ConfigItem("level", level.ToString(), ParameterMode.Raw)); // bind store var data = new List<object>(); for (int i = 1; i <= 9; i++) { data.Add(new { ID = recId.ConcatWith("_R", i), Name = "Level".ConcatWith(level, ": Row " + i) }); } //build grid var grid = new GridPanel { ID = newGridId, Store = { store }, AutoHeight = true, EnableColumnMove = level == 1 }; //build columns grid.ColumnModel.Columns.Add(new RowNumbererColumn { Width = 25 }); if (level==1) { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Name" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Class" }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Class1" }); } else { grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Name", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Class", Resizable = false }); grid.ColumnModel.Columns.Add(new Column { DataIndex = "Name", Header = "Class1", Resizable = false }); } grid.ColumnModel.ID = newGridId + "_CM"; // build view var view = new Ext.Net.GridView { ID = newGridId + "_View", ForceFit = true }; grid.View.Add(view); // build selection model var sm = new RowSelectionModel { ID = newGridId + "_SM" }; if (level != 3) { sm.Listeners.BeforeRowSelect.Handler = "return false;";//合计类不允许选择 } grid.SelectionModel.Add(sm); // add expander for all levels except last (last level is 5) if (level < 3) { view.Listeners.BeforeRefresh.Fn = "clean"; var re = new RowExpander { ID = newGridId + "_RE", EnableCaching = true, Template = { ID = newGridId + "_TPL", Html = "<div id=\"row_{ID}\" style=\"background-color:white;\"></div>" } }; re.Listeners.BeforeExpand.Fn = "loadLevel"; grid.Plugins.Add(re); } store.DataSource = data; store.DataBind(); if (level == 1) { grid.Title = "MultiLevel grid"; grid.Width = 600; grid.Height = 600; grid.AutoHeight = false; //this.Form.Controls.Add(grid); Container1.Items.Add(grid); grid.Plugins.Add(new PanelResizer()); } else { var renderEl = "row_" + recId; X.Get(renderEl).SwallowEvent(new string[] { "click", "mousedown", "mouseup", "dblclick" }, true); this.RemoveFromCache(newGridId, gridId); grid.Render(renderEl, RenderMode.RenderTo); this.AddToCache(newGridId, gridId); } }