private string GetStartupOptions(bool subGrid) { StringBuilder stringBuilder = new StringBuilder(); string arg = subGrid ? "jQuery('#' + subgrid_table_id)" : string.Format("jQuery('#{0}')", this._grid.ClientID); string arg2 = subGrid ? "jQuery('#' + pager_id)" : string.Format("jQuery('#{0}')", this._grid.ClientID + "_pager"); string pagerSelectorID = subGrid ? "'#' + pager_id" : string.Format("'#{0}'", this._grid.ClientID + "_pager"); string text = subGrid ? "&parentRowID=' + encodeURIComponent(row_id) + '" : string.Empty; string text2 = (this._grid.DataUrl.IndexOf("?") > 0) ? "&" : "?"; string text3 = (this._grid.EditUrl.IndexOf("?") > 0) ? "&" : "?"; string arg3 = string.Format("{0}{1}jqGridID={2}{3}", new object[] { this._grid.DataUrl, text2, this._grid.ClientID, text }); string arg4 = string.Format("{0}{1}jqGridID={2}&editMode=1{3}", new object[] { this._grid.EditUrl, text3, this._grid.ClientID, text }); if (this._grid.Columns.Count > 0 && this._grid.Columns[0].Frozen) { this._grid.AppearanceSettings.ShrinkToFit = false; } stringBuilder.AppendFormat("{0}.jqGrid({{", arg); stringBuilder.AppendFormat("url: '{0}'", arg3); stringBuilder.AppendFormat(",editurl: '{0}'", arg4); stringBuilder.AppendFormat(",datatype: 'json'", new object[0]); stringBuilder.AppendFormat(",page: {0}", this._grid.PagerSettings.CurrentPage); stringBuilder.AppendFormat(",colNames: {0}", this.GetColNames()); stringBuilder.AppendFormat(",colModel: {0}", this.GetColModel()); stringBuilder.AppendFormat(",viewrecords: true", new object[0]); stringBuilder.AppendFormat(",scrollrows: false", new object[0]); stringBuilder.AppendFormat(",postBackUrl: \"{0}\"", this._grid.Page.ClientScript.GetPostBackEventReference(this._grid, "jqGridParams")); stringBuilder.AppendFormat(",editDialogOptions: {0}", this.GetEditOptions()); stringBuilder.AppendFormat(",addDialogOptions: {0}", this.GetAddOptions()); stringBuilder.AppendFormat(",delDialogOptions: {0}", this.GetDelOptions()); stringBuilder.AppendFormat(",searchDialogOptions: {0}", this.GetSearchOptions()); stringBuilder.AppendFormat(",viewRowDetailsDialogOptions: {0}", this.GetViewRowsOptions()); string format; if (this._grid.TreeGridSettings.Enabled) { format = ",jsonReader: {{ id: \"{0}\", repeatitems:false,subgrid:{{repeatitems:false}} }}"; } else { format = ",jsonReader: {{ id: \"{0}\" }}"; } stringBuilder.AppendFormat(format, this._grid.Columns[Util.GetPrimaryKeyIndex(this._grid)].DataField); stringBuilder.AppendFormat(",rowNum: {0}", this._grid.PagerSettings.PageSize.ToString()); stringBuilder.AppendFormat(",rowList: {0}", this._grid.PagerSettings.PageSizeOptions.ToString()); stringBuilder.AppendFormat(",sortorder: '{0}'", this._grid.SortSettings.InitialSortDirection.ToString().ToLower()); stringBuilder.AppendFormat(",hidegrid: {0}", this._grid.AppearanceSettings.ShowCaptionGridToggleButton.ToString().ToLower()); if (!this._grid.Width.IsEmpty) { stringBuilder.AppendFormat(",width: '{0}'", this._grid.Width.ToString().Replace("px", "")); } if (!this._grid.Height.IsEmpty) { stringBuilder.AppendFormat(",height: '{0}'", this._grid.Height.ToString().Replace("px", "")); } if (this._grid.ColumnReordering) { stringBuilder.Append(",sortable: true"); } if (this._grid.AutoWidth) { stringBuilder.Append(",autowidth: true"); } stringBuilder.Append(",headertitles: true"); if (!this._grid.AppearanceSettings.HighlightRowsOnHover) { stringBuilder.Append(",hoverrows: false"); } if (this._grid.AppearanceSettings.AlternateRowBackground) { stringBuilder.Append(",altRows: true"); } if (this._grid.AppearanceSettings.ShowRowNumbers) { stringBuilder.Append(",rownumbers: true"); } if (this._grid.AppearanceSettings.RowNumbersColumnWidth != 25) { stringBuilder.AppendFormat(",rownumWidth: {0}", this._grid.AppearanceSettings.RowNumbersColumnWidth.ToString()); } if (!this._grid.AppearanceSettings.ShrinkToFit) { stringBuilder.Append(",shrinkToFit: false"); } if (this._grid.AppearanceSettings.ScrollBarOffset != 18) { stringBuilder.AppendFormat(",scrollOffset: {0}", this._grid.AppearanceSettings.ScrollBarOffset); } if (this._grid.AppearanceSettings.RightToLeft) { stringBuilder.Append(",direction: 'rtl'"); } if (!string.IsNullOrEmpty(this._grid.AppearanceSettings.Caption)) { stringBuilder.AppendFormat(",caption: '{0}'", this._grid.AppearanceSettings.Caption); } if (this._grid.AppearanceSettings.ShowFooter) { stringBuilder.Append(",footerrow: true"); stringBuilder.Append(",userDataOnFooter: true"); } if (this._grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.Bottom || this._grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom) { stringBuilder.AppendFormat(",pager: {0}", arg2); } if (this._grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.Top || this._grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom) { stringBuilder.Append(",toppager: true"); } if (this._grid.PagerSettings.ScrollBarPaging) { stringBuilder.AppendFormat(",scroll: 1", new object[0]); } if (!string.IsNullOrEmpty(this._grid.PagerSettings.NoRowsMessage)) { stringBuilder.AppendFormat(",emptyrecords: '{0}'", this._grid.PagerSettings.NoRowsMessage.ToString()); } if (this._grid.RenderingMode == RenderingMode.Optimized) { stringBuilder.Append(",gridview: true"); } if (!string.IsNullOrEmpty(this._grid.SortSettings.InitialSortColumn)) { stringBuilder.AppendFormat(",sortname: '{0}'", this._grid.SortSettings.InitialSortColumn); } stringBuilder.AppendFormat(",viewsortcols: [{0},'{1}',{2}]", "false", this._grid.SortSettings.SortIconsPosition.ToString().ToLower(), (this._grid.SortSettings.SortAction == SortAction.ClickOnHeader) ? "true" : "false"); if (this._grid.HierarchySettings.HierarchyMode == HierarchyMode.Parent || this._grid.HierarchySettings.HierarchyMode == HierarchyMode.ParentAndChild) { stringBuilder.Append(",subGrid: true"); Hashtable subGridOptions = this._grid.HierarchySettings.GetSubGridOptions(); if (subGridOptions.Count > 0) { stringBuilder.AppendFormat(",subGridOptions:{0}", this._grid.HierarchySettings.GetSubGridOptionsJSON()); } } if (this._grid.MultiSelect) { stringBuilder.Append(",multiselect: true"); if (this._grid.MultiSelectMode == MultiSelectMode.SelectOnCheckBoxClickOnly) { stringBuilder.AppendFormat(",multiboxonly: true", this._grid.MultiSelect.ToString().ToLower()); } if (this._grid.MultiSelectKey != MultiSelectKey.None) { stringBuilder.AppendFormat(",multikey: '{0}'", this.GetMultiKeyString(this._grid.MultiSelectKey)); } } if (this._grid.EditInlineCellSettings.Enabled) { stringBuilder.Append(",cellEdit:true"); stringBuilder.Append(",cellsubmit:'remote'"); stringBuilder.AppendFormat(",cellurl:'{0}'", arg4); } if (this._grid.GroupSettings.GroupFields.Count > 0) { stringBuilder.Append(this._grid.GroupSettings.ToJSON()); } this.RenderClientSideEvents(stringBuilder, this._grid.ClientSideEvents); if (this._grid.TreeGridSettings.Enabled) { stringBuilder.AppendFormat(",treeGrid: true", new object[0]); stringBuilder.AppendFormat(",treedatatype: 'json'", new object[0]); stringBuilder.AppendFormat(",treeGridModel: 'adjacency'", new object[0]); string arg5 = "{ level_field: 'tree_level', parent_id_field: 'tree_parent', leaf_field: 'tree_leaf', expanded_field: 'tree_expanded', loaded: 'tree_loaded', icon_field: 'tree_icon' }"; stringBuilder.AppendFormat(",treeReader: {0}", arg5); stringBuilder.AppendFormat(",ExpandColumn: '{0}'", this.GetFirstVisibleDataField(this._grid)); Hashtable hashtable = new Hashtable(); if (!string.IsNullOrEmpty(this._grid.TreeGridSettings.CollapsedIcon)) { hashtable.Add("plus", this._grid.TreeGridSettings.CollapsedIcon); } if (!string.IsNullOrEmpty(this._grid.TreeGridSettings.ExpandedIcon)) { hashtable.Add("minus", this._grid.TreeGridSettings.ExpandedIcon); } if (!string.IsNullOrEmpty(this._grid.TreeGridSettings.LeafIcon)) { hashtable.Add("leaf", this._grid.TreeGridSettings.LeafIcon); } if (hashtable.Count > 0) { stringBuilder.AppendFormat(",treeIcons: {0}", new JavaScriptSerializer().Serialize(hashtable)); } } stringBuilder.AppendFormat("}})", new object[0]); stringBuilder.Append(this.GetToolBarOptions(subGrid, pagerSelectorID)); if (!this._grid.PagerSettings.ScrollBarPaging && this._grid.KeyboardNavigation) { stringBuilder.AppendFormat(".bindKeys()", new object[0]); } JsonInlineToolBar jsonInlineToolBar = new JsonInlineToolBar(this._grid.ToolBarSettings); if (!jsonInlineToolBar.IsEmpty()) { stringBuilder.AppendFormat(".inlineNav({0},{1})", this.GetToolBarID(), jsonInlineToolBar.ToJSON()); } stringBuilder.Append(";"); stringBuilder.Append(this.GetLoadErrorHandler()); stringBuilder.Append(";"); if (this._grid.HeaderGroups.Count > 0) { List<Hashtable> list = new List<Hashtable>(); foreach (JQGridHeaderGroup jQGridHeaderGroup in this._grid.HeaderGroups) { list.Add(jQGridHeaderGroup.ToHashtable()); } stringBuilder.AppendFormat("{0}.setGroupHeaders( {{ useColSpanStyle:true,groupHeaders:{1} }});", arg, new JavaScriptSerializer().Serialize(list)); } if (!subGrid) { stringBuilder.Append(this.GetJQuerySubmit()); stringBuilder.Append(this.GetSelectedRowPostBack()); stringBuilder.Append(this.RestoreSelectedState()); } if (this._grid.ToolBarSettings.ShowSearchToolBar) { stringBuilder.AppendFormat("{0}.filterToolbar({1});", arg, new JsonSearchToolBar(this._grid).Process()); } if (this._grid.Columns.Count > 0 && this._grid.Columns[0].Frozen) { stringBuilder.AppendFormat("{0}.setFrozenColumns();", arg); } return stringBuilder.ToString(); }
private string GetStartupOptions(bool subGrid) { StringBuilder stringBuilder = new StringBuilder(); string arg = subGrid ? "jQuery('#' + subgrid_table_id)" : string.Format("jQuery('#{0}')", this._grid.ClientID); string arg2 = subGrid ? "jQuery('#' + pager_id)" : string.Format("jQuery('#{0}')", this._grid.ClientID + "_pager"); string pagerSelectorID = subGrid ? "'#' + pager_id" : string.Format("'#{0}'", this._grid.ClientID + "_pager"); string text = subGrid ? "&parentRowID=' + encodeURIComponent(row_id) + '" : string.Empty; string text2 = (this._grid.DataUrl.IndexOf("?") > 0) ? "&" : "?"; string text3 = (this._grid.EditUrl.IndexOf("?") > 0) ? "&" : "?"; string arg3 = string.Format("{0}{1}jqGridID={2}{3}", new object[] { this._grid.DataUrl, text2, this._grid.ClientID, text }); string arg4 = string.Format("{0}{1}jqGridID={2}&editMode=1{3}", new object[] { this._grid.EditUrl, text3, this._grid.ClientID, text }); if (this._grid.Columns.Count > 0 && this._grid.Columns[0].Frozen) { this._grid.AppearanceSettings.ShrinkToFit = false; } stringBuilder.AppendFormat("{0}.jqGrid({{", arg); stringBuilder.AppendFormat("url: '{0}'", arg3); stringBuilder.AppendFormat(",editurl: '{0}'", arg4); stringBuilder.AppendFormat(",datatype: 'json'", new object[0]); stringBuilder.AppendFormat(",page: {0}", this._grid.PagerSettings.CurrentPage); stringBuilder.AppendFormat(",colNames: {0}", this.GetColNames()); stringBuilder.AppendFormat(",colModel: {0}", this.GetColModel()); stringBuilder.AppendFormat(",viewrecords: true", new object[0]); stringBuilder.AppendFormat(",scrollrows: false", new object[0]); stringBuilder.AppendFormat(",postBackUrl: \"{0}\"", this._grid.Page.ClientScript.GetPostBackEventReference(this._grid, "jqGridParams")); stringBuilder.AppendFormat(",editDialogOptions: {0}", this.GetEditOptions()); stringBuilder.AppendFormat(",addDialogOptions: {0}", this.GetAddOptions()); stringBuilder.AppendFormat(",delDialogOptions: {0}", this.GetDelOptions()); stringBuilder.AppendFormat(",searchDialogOptions: {0}", this.GetSearchOptions()); stringBuilder.AppendFormat(",viewRowDetailsDialogOptions: {0}", this.GetViewRowsOptions()); string format; if (this._grid.TreeGridSettings.Enabled) { format = ",jsonReader: {{ id: \"{0}\", repeatitems:false,subgrid:{{repeatitems:false}} }}"; } else { format = ",jsonReader: {{ id: \"{0}\" }}"; } stringBuilder.AppendFormat(format, this._grid.Columns[Util.GetPrimaryKeyIndex(this._grid)].DataField); stringBuilder.AppendFormat(",rowNum: {0}", this._grid.PagerSettings.PageSize.ToString()); stringBuilder.AppendFormat(",rowList: {0}", this._grid.PagerSettings.PageSizeOptions.ToString()); stringBuilder.AppendFormat(",sortorder: '{0}'", this._grid.SortSettings.InitialSortDirection.ToString().ToLower()); stringBuilder.AppendFormat(",hidegrid: {0}", this._grid.AppearanceSettings.ShowCaptionGridToggleButton.ToString().ToLower()); if (!this._grid.Width.IsEmpty) { stringBuilder.AppendFormat(",width: '{0}'", this._grid.Width.ToString().Replace("px", "")); } if (!this._grid.Height.IsEmpty) { stringBuilder.AppendFormat(",height: '{0}'", this._grid.Height.ToString().Replace("px", "")); } if (this._grid.ColumnReordering) { stringBuilder.Append(",sortable: true"); } if (this._grid.AutoWidth) { stringBuilder.Append(",autowidth: true"); } stringBuilder.Append(",headertitles: true"); if (!this._grid.AppearanceSettings.HighlightRowsOnHover) { stringBuilder.Append(",hoverrows: false"); } if (this._grid.AppearanceSettings.AlternateRowBackground) { stringBuilder.Append(",altRows: true"); } if (this._grid.AppearanceSettings.ShowRowNumbers) { stringBuilder.Append(",rownumbers: true"); } if (this._grid.AppearanceSettings.RowNumbersColumnWidth != 25) { stringBuilder.AppendFormat(",rownumWidth: {0}", this._grid.AppearanceSettings.RowNumbersColumnWidth.ToString()); } if (!this._grid.AppearanceSettings.ShrinkToFit) { stringBuilder.Append(",shrinkToFit: false"); } if (this._grid.AppearanceSettings.ScrollBarOffset != 18) { stringBuilder.AppendFormat(",scrollOffset: {0}", this._grid.AppearanceSettings.ScrollBarOffset); } if (this._grid.AppearanceSettings.RightToLeft) { stringBuilder.Append(",direction: 'rtl'"); } if (!string.IsNullOrEmpty(this._grid.AppearanceSettings.Caption)) { stringBuilder.AppendFormat(",caption: '{0}'", this._grid.AppearanceSettings.Caption); } if (this._grid.AppearanceSettings.ShowFooter) { stringBuilder.Append(",footerrow: true"); stringBuilder.Append(",userDataOnFooter: true"); } if (this._grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.Bottom || this._grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom) { stringBuilder.AppendFormat(",pager: {0}", arg2); } if (this._grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.Top || this._grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom) { stringBuilder.Append(",toppager: true"); } if (this._grid.PagerSettings.ScrollBarPaging) { stringBuilder.AppendFormat(",scroll: 1", new object[0]); } if (!string.IsNullOrEmpty(this._grid.PagerSettings.NoRowsMessage)) { stringBuilder.AppendFormat(",emptyrecords: '{0}'", this._grid.PagerSettings.NoRowsMessage.ToString()); } if (this._grid.RenderingMode == RenderingMode.Optimized) { stringBuilder.Append(",gridview: true"); } if (!string.IsNullOrEmpty(this._grid.SortSettings.InitialSortColumn)) { stringBuilder.AppendFormat(",sortname: '{0}'", this._grid.SortSettings.InitialSortColumn); } stringBuilder.AppendFormat(",viewsortcols: [{0},'{1}',{2}]", "false", this._grid.SortSettings.SortIconsPosition.ToString().ToLower(), (this._grid.SortSettings.SortAction == SortAction.ClickOnHeader) ? "true" : "false"); if (this._grid.HierarchySettings.HierarchyMode == HierarchyMode.Parent || this._grid.HierarchySettings.HierarchyMode == HierarchyMode.ParentAndChild) { stringBuilder.Append(",subGrid: true"); Hashtable subGridOptions = this._grid.HierarchySettings.GetSubGridOptions(); if (subGridOptions.Count > 0) { stringBuilder.AppendFormat(",subGridOptions:{0}", this._grid.HierarchySettings.GetSubGridOptionsJSON()); } } if (this._grid.MultiSelect) { stringBuilder.Append(",multiselect: true"); if (this._grid.MultiSelectMode == MultiSelectMode.SelectOnCheckBoxClickOnly) { stringBuilder.AppendFormat(",multiboxonly: true", this._grid.MultiSelect.ToString().ToLower()); } if (this._grid.MultiSelectKey != MultiSelectKey.None) { stringBuilder.AppendFormat(",multikey: '{0}'", this.GetMultiKeyString(this._grid.MultiSelectKey)); } } if (this._grid.EditInlineCellSettings.Enabled) { stringBuilder.Append(",cellEdit:true"); stringBuilder.Append(",cellsubmit:'remote'"); stringBuilder.AppendFormat(",cellurl:'{0}'", arg4); } if (this._grid.GroupSettings.GroupFields.Count > 0) { stringBuilder.Append(this._grid.GroupSettings.ToJSON()); } this.RenderClientSideEvents(stringBuilder, this._grid.ClientSideEvents); if (this._grid.TreeGridSettings.Enabled) { stringBuilder.AppendFormat(",treeGrid: true", new object[0]); stringBuilder.AppendFormat(",treedatatype: 'json'", new object[0]); stringBuilder.AppendFormat(",treeGridModel: 'adjacency'", new object[0]); string arg5 = "{ level_field: 'tree_level', parent_id_field: 'tree_parent', leaf_field: 'tree_leaf', expanded_field: 'tree_expanded', loaded: 'tree_loaded', icon_field: 'tree_icon' }"; stringBuilder.AppendFormat(",treeReader: {0}", arg5); stringBuilder.AppendFormat(",ExpandColumn: '{0}'", this.GetFirstVisibleDataField(this._grid)); Hashtable hashtable = new Hashtable(); if (!string.IsNullOrEmpty(this._grid.TreeGridSettings.CollapsedIcon)) { hashtable.Add("plus", this._grid.TreeGridSettings.CollapsedIcon); } if (!string.IsNullOrEmpty(this._grid.TreeGridSettings.ExpandedIcon)) { hashtable.Add("minus", this._grid.TreeGridSettings.ExpandedIcon); } if (!string.IsNullOrEmpty(this._grid.TreeGridSettings.LeafIcon)) { hashtable.Add("leaf", this._grid.TreeGridSettings.LeafIcon); } if (hashtable.Count > 0) { stringBuilder.AppendFormat(",treeIcons: {0}", new JavaScriptSerializer().Serialize(hashtable)); } } stringBuilder.AppendFormat("}})", new object[0]); stringBuilder.Append(this.GetToolBarOptions(subGrid, pagerSelectorID)); if (!this._grid.PagerSettings.ScrollBarPaging && this._grid.KeyboardNavigation) { stringBuilder.AppendFormat(".bindKeys()", new object[0]); } JsonInlineToolBar jsonInlineToolBar = new JsonInlineToolBar(this._grid.ToolBarSettings); if (!jsonInlineToolBar.IsEmpty()) { stringBuilder.AppendFormat(".inlineNav({0},{1})", this.GetToolBarID(), jsonInlineToolBar.ToJSON()); } stringBuilder.Append(";"); stringBuilder.Append(this.GetLoadErrorHandler()); stringBuilder.Append(";"); if (this._grid.HeaderGroups.Count > 0) { List <Hashtable> list = new List <Hashtable>(); foreach (JQGridHeaderGroup jQGridHeaderGroup in this._grid.HeaderGroups) { list.Add(jQGridHeaderGroup.ToHashtable()); } stringBuilder.AppendFormat("{0}.setGroupHeaders( {{ useColSpanStyle:true,groupHeaders:{1} }});", arg, new JavaScriptSerializer().Serialize(list)); } if (!subGrid) { stringBuilder.Append(this.GetJQuerySubmit()); stringBuilder.Append(this.GetSelectedRowPostBack()); stringBuilder.Append(this.RestoreSelectedState()); } if (this._grid.ToolBarSettings.ShowSearchToolBar) { stringBuilder.AppendFormat("{0}.filterToolbar({1});", arg, new JsonSearchToolBar(this._grid).Process()); } if (this._grid.Columns.Count > 0 && this._grid.Columns[0].Frozen) { stringBuilder.AppendFormat("{0}.setFrozenColumns();", arg); } return(stringBuilder.ToString()); }