private static string ConstructLinqFilterExpression(JQGrid grid, Util.SearchArguments args) { JQGridColumn jQGridColumn = grid.Columns.Find((JQGridColumn c) => c.DataField == args.SearchColumn); if (jQGridColumn == null) { throw new Exception("JqGridColumn ûÓÐÉèÖÃ"); } if (jQGridColumn.DataType == null) { throw new DataTypeNotSetException("JQGridColumn.DataType must be set in order to perform search operations."); } string filterExpressionCompare = (jQGridColumn.DataType == typeof(string)) ? "{0} {1} \"{2}\"" : "{0} {1} {2}"; if (jQGridColumn.DataType == typeof(DateTime)) { if (!string.IsNullOrEmpty(args.SearchString)) { DateTime dateTime = DateTime.Parse(args.SearchString); string str = string.Format("({0},{1},{2},{3},{4},{5})", dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second); filterExpressionCompare = "{0} {1} DateTime" + str; } } //string str2 = string.Format("{0} != null AND ", args.SearchColumn); string str2 = ""; if (jQGridColumn.DataType == typeof(Guid)) { filterExpressionCompare = "{0} {1} Guid(\"{2}\")"; //str2 = "";//string.Format("{0} != Guid.Empty AND ", args.SearchColumn); } return(str2 + Util.GetLinqExpression(filterExpressionCompare, args, jQGridColumn.SearchCaseSensitive, jQGridColumn.DataType)); }
public static DataTable ToDataTable(this IEnumerable en, JQAutoComplete autoComplete) { JQGrid grid = new JQGrid(); JQGridColumn item = new JQGridColumn(); item.DataField = autoComplete.DataField; grid.Columns.Add(item); return(en.ToDataTable(grid)); }
public static DataTable ToDataTable(this IEnumerable en, JQAutoComplete autoComplete) { JQGrid grid = new JQGrid(); JQGridColumn item = new JQGridColumn { DataField = autoComplete.DataField }; grid.Columns.Add(item); return en.ToDataTable(grid); }
private string GetColNames(JQGrid grid) { string[] array = new string[grid.Columns.Count]; for (int i = 0; i < grid.Columns.Count; i++) { JQGridColumn jQGridColumn = grid.Columns[i]; array[i] = (string.IsNullOrEmpty(jQGridColumn.HeaderText) ? jQGridColumn.DataField : jQGridColumn.HeaderText); } return(new JavaScriptSerializer().Serialize(array)); }
private string GetColNames(JQGrid grid) { List <string> lTreeGridColumn = new List <string>(); lTreeGridColumn.Add("level"); lTreeGridColumn.Add("parent_id"); lTreeGridColumn.Add("isLeaf"); lTreeGridColumn.Add("expanded"); grid.Columns.RemoveAll(g => lTreeGridColumn.Contains(g.DataField)); string[] strArray = new string[grid.Columns.Count]; for (int i = 0; i < grid.Columns.Count; i++) { //if (lTreeGridColumn.Contains(grid.Columns[i].DataField)) continue; JQGridColumn column = grid.Columns[i]; strArray[i] = string.IsNullOrEmpty(column.HeaderText) ? column.DataField : column.HeaderText; } return(new JavaScriptSerializer().Serialize(strArray)); }
private static string ConstructLinqFilterExpression(JQGrid grid, SearchArguments args) { JQGridColumn column = grid.Columns.Find(delegate(JQGridColumn c) { return(c.DataField == args.SearchColumn); }); if (column.DataType == null) { throw new DataTypeNotSetException("JQGridColumn.DataType must be set in order to perform search operations."); } string filterExpressionCompare = (column.DataType == typeof(string)) ? "{0} {1} \"{2}\"" : "{0} {1} {2}"; if (column.DataType == typeof(DateTime)) { DateTime time = DateTime.Parse(args.SearchString); string str2 = string.Format("({0},{1},{2})", time.Year, time.Month, time.Day); filterExpressionCompare = "{0} {1} DateTime" + str2; } return(string.Format("{0} != null AND ", args.SearchColumn) + GetLinqExpression(filterExpressionCompare, args, column.SearchCaseSensitive, column.DataType)); }
internal static JsonResponse PrepareJsonResponse(JsonResponse response, JQGrid grid, DataTable dt) { for (int i = 0; i < dt.Rows.Count; i++) { string[] array = new string[grid.Columns.Count]; for (int j = 0; j < grid.Columns.Count; j++) { JQGridColumn jQGridColumn = grid.Columns[j]; string text = ""; if (!string.IsNullOrEmpty(jQGridColumn.DataField)) { int ordinal = dt.Columns[jQGridColumn.DataField].Ordinal; text = (string.IsNullOrEmpty(jQGridColumn.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : jQGridColumn.FormatDataValue(dt.Rows[i].ItemArray[ordinal], jQGridColumn.HtmlEncode)); } array[j] = text; } string id = array[Util.GetPrimaryKeyIndex(grid)]; JsonRow jsonRow = new JsonRow(); jsonRow.id = id; jsonRow.cell = array; response.rows[i] = jsonRow; } return(response); }
internal static JsonResponse PrepareJsonResponse(JsonResponse response, JQGrid grid, DataTable dt) { for (int i = 0; i < dt.Rows.Count; i++) { string[] strArray = new string[grid.Columns.Count]; for (int j = 0; j < grid.Columns.Count; j++) { JQGridColumn column = grid.Columns[j]; string str = ""; if (!string.IsNullOrEmpty(column.DataField)) { int ordinal = dt.Columns[column.DataField].Ordinal; str = string.IsNullOrEmpty(column.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : column.FormatDataValue(dt.Rows[i].ItemArray[ordinal], column.HtmlEncode); } strArray[j] = str; } string str2 = strArray[GetPrimaryKeyIndex(grid)]; JsonRow row = new JsonRow(); row.id = str2; row.cell = strArray; response.rows[i] = row; } return(response); }
public List <JQGridColumn> GetColumns(Type t) { List <JQGridColumn> ljc = new List <JQGridColumn>(); PropertyInfo[] members = t.GetProperties(); foreach (PropertyInfo member in members) { JQGridColumn col = new JQGridColumn(); col.DataField = member.Name; col.DataType = member.PropertyType; col.Editable = true; if (col.DataType == typeof(decimal) || col.DataType == typeof(int)) { col.EditClientSideValidators.Add(new NumberValidator()); col.Formatter = new CustomFormatter() { FormatFunction = "FormatNumber", UnFormatFunction = "UnFormatNumber" }; } ShowAttribute(member, col); ljc.Add(col); } return(ljc.OrderBy(o => o.Order).ToList()); }
public void FromColumn(JQGridColumn column) { this._jsonValues["index"] = this._jsonValues["name"] = column.DataField; if (column.Width != 150) { this._jsonValues["width"] = column.Width; } if (!column.Sortable) { this._jsonValues["sortable"] = false; } if (column.PrimaryKey) { this._jsonValues["key"] = true; } if (!column.Visible) { this._jsonValues["hidden"] = true; } if (!column.Searchable) { this._jsonValues["search"] = false; } if (column.TextAlign != TextAlign.Left) { this._jsonValues["align"] = column.TextAlign.ToString().ToLower(); } if (!column.Resizable) { this._jsonValues["resizable"] = false; } if (column.Frozen) { this._jsonValues["frozen"] = true; } if (!string.IsNullOrEmpty(column.CssClass)) { this._jsonValues["classes"] = column.CssClass; } if (column.Fixed) { this._jsonValues["fixed"] = true; } switch (column.GroupSummaryType) { case GroupSummaryType.Min: this._jsonValues["summaryType"] = "min"; break; case GroupSummaryType.Max: this._jsonValues["summaryType"] = "max"; break; case GroupSummaryType.Sum: this._jsonValues["summaryType"] = "sum"; break; case GroupSummaryType.Avg: this._jsonValues["summaryType"] = "avg"; break; case GroupSummaryType.Count: this._jsonValues["summaryType"] = "count"; break; } if (!string.IsNullOrEmpty(column.GroupTemplate)) { this._jsonValues["summaryTpl"] = column.GroupTemplate; } if ((column.Formatter != null) || column.EditActionIconsColumn) { this.ApplyFormatterOptions(column); } if (column.EditActionIconsColumn) { this._jsonValues["formatter"] = "actions"; } if (column.Searchable) { Hashtable hashtable = new Hashtable(); if (column.SearchType == SearchType.DropDown) { this._jsonValues["stype"] = "select"; } if (!column.Visible) { hashtable["searchhidden"] = true; } if (column.SearchList.Count<SelectListItem>() > 0) { StringBuilder builder = new StringBuilder(); int num = 0; foreach (SelectListItem item in column.SearchList) { builder.AppendFormat("{0}:{1}", item.Value, item.Text); num++; if (num < column.SearchList.Count<SelectListItem>()) { builder.Append(";"); } if (item.Selected) { hashtable["defaultValue"] = item.Value; } } hashtable["value"] = builder.ToString(); } if ((column.SearchType == SearchType.DatePicker) || (column.SearchType == SearchType.AutoComplete)) { hashtable["dataInit"] = "attachSearchControlsScript" + column.DataField; } this._jsonValues["searchoptions"] = hashtable; } if (column.Editable) { Hashtable hashtable2 = new Hashtable(); this._jsonValues["editable"] = true; if (column.EditType != EditType.TextBox) { this._jsonValues["edittype"] = this.GetEditType(column.EditType); } if (column.EditType == EditType.CheckBox) { column.EditList.Clear(); column.EditList.Add(new SelectListItem { Value = "true:false" }); } if (column.EditType == EditType.Custom) { Guard.IsNotNullOrEmpty(column.EditTypeCustomCreateElement, "JQGridColumn.EditTypeCustomCreateElement", " should be set to the name of the javascript function creating the element when EditType = EditType.Custom"); Guard.IsNotNullOrEmpty(column.EditTypeCustomGetValue, "JQGridColumn.EditTypeCustomGetValue", " should be set to the name of the javascript function getting the value from the element when EditType = EditType.Custom"); hashtable2["custom_element"] = column.EditTypeCustomCreateElement; hashtable2["custom_value"] = column.EditTypeCustomGetValue; } foreach (JQGridEditFieldAttribute attribute in column.EditFieldAttributes) { hashtable2[attribute.Name] = attribute.Value; } if ((column.EditType == EditType.DatePicker) || (column.EditType == EditType.AutoComplete)) { hashtable2["dataInit"] = "attachEditControlsScript" + column.DataField; } if (column.EditList.Count<SelectListItem>() > 0) { StringBuilder builder2 = new StringBuilder(); int num2 = 0; foreach (SelectListItem item3 in column.EditList) { builder2.AppendFormat("{0}:{1}", item3.Value, item3.Text); num2++; if (num2 < column.EditList.Count<SelectListItem>()) { builder2.Append(";"); } } hashtable2["value"] = builder2.ToString(); } if (hashtable2.Count > 0) { this._jsonValues["editoptions"] = hashtable2; } Hashtable hashtable3 = new Hashtable(); if (column.EditDialogColumnPosition != 0) { hashtable3["colpos"] = column.EditDialogColumnPosition; } if (column.EditDialogRowPosition != 0) { hashtable3["rowpos"] = column.EditDialogRowPosition; } if (!string.IsNullOrEmpty(column.EditDialogLabel)) { hashtable3["label"] = column.EditDialogLabel; } if (!string.IsNullOrEmpty(column.EditDialogFieldPrefix)) { hashtable3["elmprefix"] = column.EditDialogFieldPrefix; } if (!string.IsNullOrEmpty(column.EditDialogFieldSuffix)) { hashtable3["elmsuffix"] = column.EditDialogFieldSuffix; } if (hashtable3.Count > 0) { this._jsonValues["formoptions"] = hashtable3; } Hashtable hashtable4 = new Hashtable(); if (!column.Visible && column.Editable) { hashtable4["edithidden"] = true; } if (column.EditClientSideValidators != null) { foreach (JQGridEditClientSideValidator validator in column.EditClientSideValidators) { if (validator is DateValidator) { hashtable4["date"] = true; } if (validator is EmailValidator) { hashtable4["email"] = true; } if (validator is IntegerValidator) { hashtable4["integer"] = true; } if (validator is MaxValueValidator) { hashtable4["maxValue"] = ((MaxValueValidator) validator).MaxValue; } if (validator is MinValueValidator) { hashtable4["minValue"] = ((MinValueValidator) validator).MinValue; } if (validator is NumberValidator) { hashtable4["number"] = true; } if (validator is RequiredValidator) { hashtable4["required"] = true; } if (validator is TimeValidator) { hashtable4["time"] = true; } if (validator is UrlValidator) { hashtable4["url"] = true; } if (validator is CustomValidator) { hashtable4["custom"] = true; hashtable4["custom_func"] = ((CustomValidator) validator).ValidationFunction; } } } if (hashtable4.Count > 0) { this._jsonValues["editrules"] = hashtable4; } } }
internal static JsonTreeResponse PrepareJsonTreeResponse(JsonTreeResponse response, JQGrid grid, DataTable dt) { for (int i = 0; i < dt.Rows.Count; i++) { response.rows[i] = new Hashtable(); for (int j = 0; j < grid.Columns.Count; j++) { JQGridColumn jQGridColumn = grid.Columns[j]; string value = ""; if (!string.IsNullOrEmpty(jQGridColumn.DataField)) { int ordinal = dt.Columns[jQGridColumn.DataField].Ordinal; value = (string.IsNullOrEmpty(jQGridColumn.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : jQGridColumn.FormatDataValue(dt.Rows[i].ItemArray[ordinal], jQGridColumn.HtmlEncode)); } response.rows[i].Add(jQGridColumn.DataField, value); } try { response.rows[i].Add("tree_level", dt.Rows[i]["tree_level"] as int?); } catch { } try { response.rows[i].Add("tree_parent", Convert.ToString(dt.Rows[i]["tree_parent"])); } catch { } try { response.rows[i].Add("tree_leaf", dt.Rows[i]["tree_leaf"] as bool?); } catch { } try { response.rows[i].Add("tree_expanded", dt.Rows[i]["tree_expanded"] as bool?); } catch { } try { response.rows[i].Add("tree_loaded", dt.Rows[i]["tree_loaded"] as bool?); } catch { } try { response.rows[i].Add("tree_icon", dt.Rows[i]["tree_icon"] as string); } catch { } } return(response); }
private void ApplyFormatterOptions(JQGridColumn column) { Hashtable hashtable = new Hashtable(); if (column.EditActionIconsColumn) { hashtable["keys"] = column.EditActionIconsSettings.SaveOnEnterKeyPress; hashtable["editbutton"] = column.EditActionIconsSettings.ShowEditIcon; hashtable["delbutton"] = column.EditActionIconsSettings.ShowDeleteIcon; } if (column.Formatter != null) { JQGridColumnFormatter formatter = column.Formatter; if (formatter is LinkFormatter) { LinkFormatter formatter2 = (LinkFormatter)formatter; this._jsonValues["formatter"] = "link"; if (!string.IsNullOrEmpty(formatter2.Target)) { hashtable["target"] = formatter2.Target; } } if (formatter is EmailFormatter) { this._jsonValues["formatter"] = "email"; } if (formatter is IntegerFormatter) { IntegerFormatter formatter3 = (IntegerFormatter)formatter; this._jsonValues["formatter"] = "integer"; if (!string.IsNullOrEmpty(formatter3.ThousandsSeparator)) { hashtable["thousandsSeparator"] = formatter3.ThousandsSeparator; } if (!string.IsNullOrEmpty(formatter3.DefaultValue)) { hashtable["defaultValue"] = formatter3.DefaultValue; } } if (formatter is NumberFormatter) { NumberFormatter formatter4 = (NumberFormatter)formatter; this._jsonValues["formatter"] = "integer"; if (!string.IsNullOrEmpty(formatter4.ThousandsSeparator)) { hashtable["thousandsSeparator"] = formatter4.ThousandsSeparator; } if (!string.IsNullOrEmpty(formatter4.DefaultValue)) { hashtable["defaultValue"] = formatter4.DefaultValue; } if (!string.IsNullOrEmpty(formatter4.DecimalSeparator)) { hashtable["decimalSeparator"] = formatter4.DecimalSeparator; } if (formatter4.DecimalPlaces != -1) { hashtable["decimalPlaces"] = formatter4.DecimalPlaces; } } if (formatter is CurrencyFormatter) { CurrencyFormatter formatter5 = (CurrencyFormatter)formatter; this._jsonValues["formatter"] = "currency"; if (!string.IsNullOrEmpty(formatter5.ThousandsSeparator)) { hashtable["thousandsSeparator"] = formatter5.ThousandsSeparator; } if (!string.IsNullOrEmpty(formatter5.DefaultValue)) { hashtable["defaultValue"] = formatter5.DefaultValue; } if (!string.IsNullOrEmpty(formatter5.DecimalSeparator)) { hashtable["decimalSeparator"] = formatter5.DecimalSeparator; } if (formatter5.DecimalPlaces != -1) { hashtable["decimalPlaces"] = formatter5.DecimalPlaces; } if (!string.IsNullOrEmpty(formatter5.Prefix)) { hashtable["prefix"] = formatter5.Prefix; } if (!string.IsNullOrEmpty(formatter5.Prefix)) { hashtable["suffix"] = formatter5.Suffix; } } if (formatter is CheckBoxFormatter) { CheckBoxFormatter formatter6 = (CheckBoxFormatter)formatter; this._jsonValues["formatter"] = "checkbox"; if (formatter6.Enabled) { hashtable["disabled"] = false; } } if (formatter is CustomFormatter) { CustomFormatter formatter7 = (CustomFormatter)formatter; if (!string.IsNullOrEmpty(formatter7.FormatFunction)) { this._jsonValues["formatter"] = formatter7.FormatFunction; } if (!string.IsNullOrEmpty(formatter7.UnFormatFunction)) { this._jsonValues["unformat"] = formatter7.UnFormatFunction; } } } if (hashtable.Count > 0) { this._jsonValues["formatoptions"] = hashtable; } }
public JsonColModel(JQGridColumn column, JQGrid grid) : this(grid) { this.FromColumn(column); }
private void ShowAttribute(PropertyInfo attributeTarget, JQGridColumn col) { object[] attributes = attributeTarget.GetCustomAttributes(false); foreach (object attribute in attributes) { if (attribute is System.ComponentModel.DataAnnotations.KeyAttribute) { col.PrimaryKey = true; } if (attribute is System.ComponentModel.DataAnnotations.Schema.ColumnAttribute) { System.ComponentModel.DataAnnotations.Schema.ColumnAttribute ca = attribute as System.ComponentModel.DataAnnotations.Schema.ColumnAttribute; col.Order = ca.Order; } if (attribute is System.ComponentModel.DisplayNameAttribute) { System.ComponentModel.DisplayNameAttribute dn = attribute as System.ComponentModel.DisplayNameAttribute; col.HeaderText = dn.DisplayName; } if (attribute is System.ComponentModel.DataAnnotations.DisplayFormatAttribute) { System.ComponentModel.DataAnnotations.DisplayFormatAttribute dfa = attribute as System.ComponentModel.DataAnnotations.DisplayFormatAttribute; col.DataFormatString = dfa.DataFormatString; } if (attribute is System.ComponentModel.DataAnnotations.EditableAttribute) { System.ComponentModel.DataAnnotations.EditableAttribute ea = attribute as System.ComponentModel.DataAnnotations.EditableAttribute; col.Editable = ea.AllowEdit; } if (attribute is System.ComponentModel.DataAnnotations.RequiredAttribute) { col.EditDialogFieldSuffix = "(*)"; col.EditClientSideValidators.Add(new RequiredValidator()); } if (attribute is SearchableAttribute) { SearchableAttribute sa = attribute as SearchableAttribute; col.Searchable = sa.Searchable; } if (attribute is SearchRequiredAttribute) { SearchRequiredAttribute sa = attribute as SearchRequiredAttribute; if (sa.SearchRequired) { col.EditClientSideValidators.Add(new SearchRequiredValidator()); } } if (attribute is VisiableAttribute) { VisiableAttribute va = attribute as VisiableAttribute; col.Visible = va.Visiable; } if (attribute is EditTypeAttribute) { EditTypeAttribute ea = attribute as EditTypeAttribute; col.EditType = ea.EditType; switch (col.EditType) { case EditType.DatePicker: col.EditorControlID = "DatePicker"; break; case EditType.DateTimePicker: col.EditorControlID = "DateTimePicker"; break; case EditType.TimePicker: col.EditorControlID = "TimePicker"; break; case EditType.AutoComplete: col.EditorControlID = "AutoComplete_" + col.DataField; break; } } if (attribute is SearchTypeAttribute) { SearchTypeAttribute sa = attribute as SearchTypeAttribute; if (sa.SearchType == SearchType.CheckBox) { col.SearchType = SearchType.DropDown; List <SelectListItem> lsli = new List <SelectListItem>(); lsli.Add(new SelectListItem() { Text = "所有", Value = "" }); lsli.Add(new SelectListItem() { Text = "是", Value = "true" }); lsli.Add(new SelectListItem() { Text = "否", Value = "false" }); col.SearchList = lsli; } else { col.SearchType = sa.SearchType; } switch (col.SearchType) { case SearchType.DatePicker: col.SearchControlID = "DatePicker"; break; case SearchType.DateTimePicker: col.SearchControlID = "DateTimePicker"; break; case SearchType.TimePicker: col.SearchControlID = "TimePicker"; break; case SearchType.AutoComplete: col.SearchControlID = "AutoComplete_" + col.DataField; break; } } if (attribute is FormatterAttribute) { FormatterAttribute fa = attribute as FormatterAttribute; switch (fa.FormatterType) { case FormatterType.CheckBox: col.Formatter = new CheckBoxFormatter(); break; } } } }
public JsonColModel(JQGridColumn column, JQGrid grid) : this(grid) { this.FromColumn(column); }
private void ApplyFormatterOptions(JQGridColumn column) { Hashtable hashtable = new Hashtable(); if (column.EditActionIconsColumn) { hashtable["keys"] = column.EditActionIconsSettings.SaveOnEnterKeyPress; hashtable["editbutton"] = column.EditActionIconsSettings.ShowEditIcon; hashtable["delbutton"] = column.EditActionIconsSettings.ShowDeleteIcon; } if (column.Formatter != null) { JQGridColumnFormatter formatter = column.Formatter; if (formatter is LinkFormatter) { LinkFormatter formatter2 = (LinkFormatter) formatter; this._jsonValues["formatter"] = "link"; if (!string.IsNullOrEmpty(formatter2.Target)) { hashtable["target"] = formatter2.Target; } } if (formatter is EmailFormatter) { this._jsonValues["formatter"] = "email"; } if (formatter is IntegerFormatter) { IntegerFormatter formatter3 = (IntegerFormatter) formatter; this._jsonValues["formatter"] = "integer"; if (!string.IsNullOrEmpty(formatter3.ThousandsSeparator)) { hashtable["thousandsSeparator"] = formatter3.ThousandsSeparator; } if (!string.IsNullOrEmpty(formatter3.DefaultValue)) { hashtable["defaultValue"] = formatter3.DefaultValue; } } if (formatter is NumberFormatter) { NumberFormatter formatter4 = (NumberFormatter) formatter; this._jsonValues["formatter"] = "integer"; if (!string.IsNullOrEmpty(formatter4.ThousandsSeparator)) { hashtable["thousandsSeparator"] = formatter4.ThousandsSeparator; } if (!string.IsNullOrEmpty(formatter4.DefaultValue)) { hashtable["defaultValue"] = formatter4.DefaultValue; } if (!string.IsNullOrEmpty(formatter4.DecimalSeparator)) { hashtable["decimalSeparator"] = formatter4.DecimalSeparator; } if (formatter4.DecimalPlaces != -1) { hashtable["decimalPlaces"] = formatter4.DecimalPlaces; } } if (formatter is CurrencyFormatter) { CurrencyFormatter formatter5 = (CurrencyFormatter) formatter; this._jsonValues["formatter"] = "currency"; if (!string.IsNullOrEmpty(formatter5.ThousandsSeparator)) { hashtable["thousandsSeparator"] = formatter5.ThousandsSeparator; } if (!string.IsNullOrEmpty(formatter5.DefaultValue)) { hashtable["defaultValue"] = formatter5.DefaultValue; } if (!string.IsNullOrEmpty(formatter5.DecimalSeparator)) { hashtable["decimalSeparator"] = formatter5.DecimalSeparator; } if (formatter5.DecimalPlaces != -1) { hashtable["decimalPlaces"] = formatter5.DecimalPlaces; } if (!string.IsNullOrEmpty(formatter5.Prefix)) { hashtable["prefix"] = formatter5.Prefix; } if (!string.IsNullOrEmpty(formatter5.Prefix)) { hashtable["suffix"] = formatter5.Suffix; } } if (formatter is CheckBoxFormatter) { CheckBoxFormatter formatter6 = (CheckBoxFormatter) formatter; this._jsonValues["formatter"] = "checkbox"; if (formatter6.Enabled) { hashtable["disabled"] = false; } } if (formatter is CustomFormatter) { CustomFormatter formatter7 = (CustomFormatter) formatter; if (!string.IsNullOrEmpty(formatter7.FormatFunction)) { this._jsonValues["formatter"] = formatter7.FormatFunction; } if (!string.IsNullOrEmpty(formatter7.UnFormatFunction)) { this._jsonValues["unformat"] = formatter7.UnFormatFunction; } } } if (hashtable.Count > 0) { this._jsonValues["formatoptions"] = hashtable; } }
public void FromColumn(JQGridColumn column) { this._jsonValues["index"] = (this._jsonValues["name"] = column.DataField); if (column.Width != 150) { this._jsonValues["width"] = column.Width; } if (!column.Sortable) { this._jsonValues["sortable"] = false; } if (column.PrimaryKey) { this._jsonValues["key"] = true; } if (!column.Visible) { this._jsonValues["hidden"] = true; } if (!column.Searchable) { this._jsonValues["search"] = false; } if (!column.Viewable) { this._jsonValues["viewable"] = false; } if (column.Hidedlg) { this._jsonValues["hidedlg"] = true; } if (column.TextAlign != TextAlign.Left) { this._jsonValues["align"] = column.TextAlign.ToString().ToLower(); } if (!column.Resizable) { this._jsonValues["resizable"] = false; } if (column.Frozen) { this._jsonValues["frozen"] = true; } if (!string.IsNullOrEmpty(column.CssClass)) { this._jsonValues["classes"] = column.CssClass; } if (column.Fixed) { this._jsonValues["fixed"] = true; } if (column.GroupSummaryType != GroupSummaryType.None) { switch (column.GroupSummaryType) { case GroupSummaryType.Min: this._jsonValues["summaryType"] = "min"; break; case GroupSummaryType.Max: this._jsonValues["summaryType"] = "max"; break; case GroupSummaryType.Sum: this._jsonValues["summaryType"] = "sum"; break; case GroupSummaryType.Avg: this._jsonValues["summaryType"] = "avg"; break; case GroupSummaryType.Count: this._jsonValues["summaryType"] = "count"; break; } } if (!string.IsNullOrEmpty(column.GroupTemplate)) { this._jsonValues["summaryTpl"] = column.GroupTemplate; } if (column.Formatter != null || column.EditActionIconsColumn) { this.ApplyFormatterOptions(column); } if (column.EditActionIconsColumn) { this._jsonValues["formatter"] = "actions"; } //zhh if (column.DataType != null) { this._jsonValues["sorttype"] = column.DataType.Name.ToLower(); } if (column.Searchable) { Hashtable hashtable = new Hashtable(); if (column.SearchType == SearchType.DropDown) { this._jsonValues["stype"] = "select"; } if (!column.Visible) { hashtable["searchhidden"] = true; } if (column.SearchList.Count <SelectListItem>() > 0) { StringBuilder stringBuilder = new StringBuilder(); int num = 0; foreach (SelectListItem current in column.SearchList) { stringBuilder.AppendFormat("{0}:{1}", current.Value, current.Text); num++; if (num < column.SearchList.Count <SelectListItem>()) { stringBuilder.Append(";"); } if (current.Selected) { hashtable["defaultValue"] = current.Value; } } hashtable["value"] = stringBuilder.ToString(); } if (column.SearchType == SearchType.DatePicker || column.SearchType == SearchType.AutoComplete || column.SearchType == SearchType.DateTimePicker || column.SearchType == SearchType.TimePicker) { hashtable["dataInit"] = "attachSearchControlsScript" + column.DataField; } if (column.SearchOptions.Count > 0) { hashtable["sopt"] = this.GetSearchOptionsArray(column.SearchOptions); } this._jsonValues["searchoptions"] = hashtable; Hashtable hashtable4 = new Hashtable(); if (column.EditClientSideValidators != null) { foreach (JQGridEditClientSideValidator current4 in column.EditClientSideValidators) { if (current4 is DateValidator) { hashtable4["date"] = true; } if (current4 is EmailValidator) { hashtable4["email"] = true; } if (current4 is IntegerValidator) { hashtable4["integer"] = true; } if (current4 is MaxValueValidator) { hashtable4["maxValue"] = ((MaxValueValidator)current4).MaxValue; } if (current4 is MinValueValidator) { hashtable4["minValue"] = ((MinValueValidator)current4).MinValue; } if (current4 is NumberValidator) { hashtable4["number"] = true; } if (current4 is SearchRequiredValidator) { hashtable4["required"] = true; } if (current4 is TimeValidator) { hashtable4["time"] = true; } if (current4 is UrlValidator) { hashtable4["url"] = true; } if (current4 is CustomValidator) { hashtable4["custom"] = true; hashtable4["custom_func"] = ((CustomValidator)current4).ValidationFunction; } } } if (hashtable4.Count > 0) { this._jsonValues["searchrules"] = hashtable4; } } Hashtable hashtable2 = new Hashtable(); if (column.EditList.Count <SelectListItem>() > 0) { StringBuilder stringBuilder2 = new StringBuilder(); int num2 = 0; foreach (SelectListItem current3 in column.EditList) { stringBuilder2.AppendFormat("{0}:{1}", current3.Value, current3.Text); num2++; if (num2 < column.EditList.Count <SelectListItem>()) { stringBuilder2.Append(";"); } } hashtable2["value"] = stringBuilder2.ToString(); } if (column.Editable) { this._jsonValues["editable"] = true; if (column.EditType == EditType.CheckBox) { hashtable2["value"] = "true:false"; } if (column.EditType != EditType.TextBox) { this._jsonValues["edittype"] = this.GetEditType(column.EditType); } if (column.EditType == EditType.CheckBox) { column.EditList.Clear(); column.EditList.Add(new SelectListItem { Value = "true:false" }); } if (column.EditType == EditType.Custom) { Guard.IsNotNullOrEmpty(column.EditTypeCustomCreateElement, "JQGridColumn.EditTypeCustomCreateElement", " should be set to the name of the javascript function creating the element when EditType = EditType.Custom"); Guard.IsNotNullOrEmpty(column.EditTypeCustomGetValue, "JQGridColumn.EditTypeCustomGetValue", " should be set to the name of the javascript function getting the value from the element when EditType = EditType.Custom"); hashtable2["custom_element"] = column.EditTypeCustomCreateElement; hashtable2["custom_value"] = column.EditTypeCustomGetValue; } foreach (JQGridEditFieldAttribute current2 in column.EditFieldAttributes) { hashtable2[current2.Name] = current2.Value; } if (column.EditType == EditType.DatePicker || column.EditType == EditType.DateTimePicker || column.EditType == EditType.TimePicker || column.EditType == EditType.AutoComplete || column.EditType == EditType.Chosen) { hashtable2["dataInit"] = "attachEditControlsScript" + column.DataField; } if (column.DataEvents.Count <DataEvent>() > 0) { //zhh 20120825 List <DataEvent> lde = column.DataEvents.FindAll(f => f.Type != DataEventType.No); if (lde.Count > 0) { Hashtable[] al = new Hashtable[lde.Count]; for (int i = 0; i < lde.Count; i++) { Hashtable ht = new Hashtable(); ht["type"] = GetDateEventType(lde[i].Type); ht["fn"] = lde[i].Function; al[i] = ht; } //string input = new JavaScriptSerializer().Serialize(al); hashtable2["dataEvents"] = al;//RemoveQuotesForJavaScriptMethods(input,lde); } } if (!string.IsNullOrEmpty(column.DefaultValue)) { hashtable2["defaultValue"] = column.DefaultValue; } if (column.EditType == EditType.DropDown) { if (!string.IsNullOrEmpty(column.DataUrl)) { hashtable2["dataUrl"] = column.DataUrl; } if (!string.IsNullOrEmpty(column.BuildSelect)) { hashtable2["buildSelect"] = column.BuildSelect; } if (!string.IsNullOrEmpty(column.SerializeColumnData)) { hashtable2["postData"] = column.SerializeColumnData; } //if (!string.IsNullOrEmpty(column.Complete)) //{ // hashtable2["complete"] = column.Complete; //} } if (!string.IsNullOrEmpty(column.DataInit)) { hashtable2["dataInit"] = column.DataInit; } Hashtable hashtable3 = new Hashtable(); if (column.EditDialogColumnPosition != 0) { hashtable3["colpos"] = column.EditDialogColumnPosition; } if (column.EditDialogRowPosition != 0) { hashtable3["rowpos"] = column.EditDialogRowPosition; } if (!string.IsNullOrEmpty(column.EditDialogLabel)) { hashtable3["label"] = column.EditDialogLabel; } if (!string.IsNullOrEmpty(column.EditDialogFieldPrefix)) { hashtable3["elmprefix"] = column.EditDialogFieldPrefix; } if (!string.IsNullOrEmpty(column.EditDialogFieldSuffix)) { hashtable3["elmsuffix"] = column.EditDialogFieldSuffix; } if (hashtable3.Count > 0) { this._jsonValues["formoptions"] = hashtable3; } Hashtable hashtable4 = new Hashtable(); if (!column.Visible && column.Editable) { hashtable4["edithidden"] = true; } if (column.EditClientSideValidators != null) { foreach (JQGridEditClientSideValidator current4 in column.EditClientSideValidators) { if (current4 is DateValidator) { hashtable4["date"] = true; } if (current4 is EmailValidator) { hashtable4["email"] = true; } if (current4 is IntegerValidator) { hashtable4["integer"] = true; } if (current4 is MaxValueValidator) { hashtable4["maxValue"] = ((MaxValueValidator)current4).MaxValue; } if (current4 is MinValueValidator) { hashtable4["minValue"] = ((MinValueValidator)current4).MinValue; } if (current4 is NumberValidator) { hashtable4["number"] = true; } if (current4 is RequiredValidator) { hashtable4["required"] = true; } if (current4 is TimeValidator) { hashtable4["time"] = true; } if (current4 is UrlValidator) { hashtable4["url"] = true; } if (current4 is CustomValidator) { hashtable4["custom"] = true; hashtable4["custom_func"] = ((CustomValidator)current4).ValidationFunction; } } } if (hashtable4.Count > 0) { this._jsonValues["editrules"] = hashtable4; } } if (hashtable2.Count > 0) { this._jsonValues["editoptions"] = hashtable2; } }
private void ApplyFormatterOptions(JQGridColumn column) { Hashtable hashtable = new Hashtable(); if (column.EditActionIconsColumn) { hashtable["keys"] = column.EditActionIconsSettings.SaveOnEnterKeyPress; hashtable["editbutton"] = column.EditActionIconsSettings.ShowEditIcon; if (column.EditActionIconsSettings.ShowEditIcon && !string.IsNullOrEmpty(column.EditActionIconsSettings.onEdit)) { hashtable["onEdit"] = column.EditActionIconsSettings.onEdit;; //editOptions : {} } hashtable["delbutton"] = column.EditActionIconsSettings.ShowDeleteIcon; if (column.EditActionIconsSettings.ShowDeleteIcon) { Hashtable ht2 = new Hashtable(); if (!string.IsNullOrEmpty(column.EditActionIconsSettings.DelErrorTextFormat)) { ht2["errorTextFormat"] = column.EditActionIconsSettings.DelErrorTextFormat; } if (!string.IsNullOrEmpty(_grid.ClientSideEvents.SerializeDelData)) { ht2["serializeDelData"] = _grid.ClientSideEvents.SerializeDelData; } if (ht2.Count > 0) { hashtable["delOptions"] = ht2; } } } if (column.Formatter != null) { JQGridColumnFormatter formatter = column.Formatter; if (formatter is LinkFormatter) { LinkFormatter linkFormatter = (LinkFormatter)formatter; this._jsonValues["formatter"] = "link"; if (!string.IsNullOrEmpty(linkFormatter.Target)) { hashtable["target"] = linkFormatter.Target; } } if (formatter is EmailFormatter) { this._jsonValues["formatter"] = "email"; } if (formatter is IntegerFormatter) { IntegerFormatter integerFormatter = (IntegerFormatter)formatter; this._jsonValues["formatter"] = "integer"; if (!string.IsNullOrEmpty(integerFormatter.ThousandsSeparator)) { hashtable["thousandsSeparator"] = integerFormatter.ThousandsSeparator; } if (!string.IsNullOrEmpty(integerFormatter.DefaultValue)) { hashtable["defaultValue"] = integerFormatter.DefaultValue; } } if (formatter is NumberFormatter) { NumberFormatter numberFormatter = (NumberFormatter)formatter; this._jsonValues["formatter"] = "integer"; if (!string.IsNullOrEmpty(numberFormatter.ThousandsSeparator)) { hashtable["thousandsSeparator"] = numberFormatter.ThousandsSeparator; } if (!string.IsNullOrEmpty(numberFormatter.DefaultValue)) { hashtable["defaultValue"] = numberFormatter.DefaultValue; } if (!string.IsNullOrEmpty(numberFormatter.DecimalSeparator)) { hashtable["decimalSeparator"] = numberFormatter.DecimalSeparator; } if (numberFormatter.DecimalPlaces != -1) { hashtable["decimalPlaces"] = numberFormatter.DecimalPlaces; } } if (formatter is CurrencyFormatter) { CurrencyFormatter currencyFormatter = (CurrencyFormatter)formatter; this._jsonValues["formatter"] = "currency"; if (!string.IsNullOrEmpty(currencyFormatter.ThousandsSeparator)) { hashtable["thousandsSeparator"] = currencyFormatter.ThousandsSeparator; } if (!string.IsNullOrEmpty(currencyFormatter.DefaultValue)) { hashtable["defaultValue"] = currencyFormatter.DefaultValue; } if (!string.IsNullOrEmpty(currencyFormatter.DecimalSeparator)) { hashtable["decimalSeparator"] = currencyFormatter.DecimalSeparator; } if (currencyFormatter.DecimalPlaces != -1) { hashtable["decimalPlaces"] = currencyFormatter.DecimalPlaces; } if (!string.IsNullOrEmpty(currencyFormatter.Prefix)) { hashtable["prefix"] = currencyFormatter.Prefix; } if (!string.IsNullOrEmpty(currencyFormatter.Prefix)) { hashtable["suffix"] = currencyFormatter.Suffix; } } if (formatter is CheckBoxFormatter) { CheckBoxFormatter checkBoxFormatter = (CheckBoxFormatter)formatter; this._jsonValues["formatter"] = "checkbox"; if (checkBoxFormatter.Enabled) { hashtable["disabled"] = false; } } if (formatter is DropDownFormatter) { this._jsonValues["formatter"] = "select"; } if (formatter is CustomFormatter) { CustomFormatter customFormatter = (CustomFormatter)formatter; if (!string.IsNullOrEmpty(customFormatter.FormatFunction)) { this._jsonValues["formatter"] = customFormatter.FormatFunction; } if (!string.IsNullOrEmpty(customFormatter.UnFormatFunction)) { this._jsonValues["unformat"] = customFormatter.UnFormatFunction; } } } if (hashtable.Count > 0) { this._jsonValues["formatoptions"] = hashtable; } }
public void FromColumn(JQGridColumn column) { this._jsonValues["index"] = this._jsonValues["name"] = column.DataField; if (column.Width != 150) { this._jsonValues["width"] = column.Width; } if (!column.Sortable) { this._jsonValues["sortable"] = false; } if (column.PrimaryKey) { this._jsonValues["key"] = true; } if (!column.Visible) { this._jsonValues["hidden"] = true; } if (!column.Searchable) { this._jsonValues["search"] = false; } if (column.TextAlign != TextAlign.Left) { this._jsonValues["align"] = column.TextAlign.ToString().ToLower(); } if (!column.Resizable) { this._jsonValues["resizable"] = false; } if (!string.IsNullOrEmpty(column.CssClass)) { this._jsonValues["classes"] = column.CssClass; } if (column.Fixed) { this._jsonValues["fixed"] = true; } switch (column.GroupSummaryType) { case GroupSummaryType.Min: this._jsonValues["summaryType"] = "min"; break; case GroupSummaryType.Max: this._jsonValues["summaryType"] = "max"; break; case GroupSummaryType.Sum: this._jsonValues["summaryType"] = "sum"; break; case GroupSummaryType.Avg: this._jsonValues["summaryType"] = "avg"; break; case GroupSummaryType.Count: this._jsonValues["summaryType"] = "count"; break; } if (!string.IsNullOrEmpty(column.GroupTemplate)) { this._jsonValues["summaryTpl"] = column.GroupTemplate; } if ((column.Formatter != null) || column.EditActionIconsColumn) { this.ApplyFormatterOptions(column); } if (column.EditActionIconsColumn) { this._jsonValues["formatter"] = "actions"; } if (column.Searchable) { if (column.SearchType == SearchType.DropDown) { this._jsonValues["stype"] = "select"; } Hashtable hashtable = new Hashtable(); if (column.SearchList.Count <SelectListItem>() > 0) { StringBuilder builder = new StringBuilder(); int num = 0; foreach (SelectListItem item in column.SearchList) { builder.AppendFormat("{0}:{1}", item.Value, item.Text); num++; if (num < column.SearchList.Count <SelectListItem>()) { builder.Append(";"); } } hashtable["value"] = builder.ToString(); } if ((column.SearchType == SearchType.DatePicker) || (column.SearchType == SearchType.AutoComplete)) { hashtable["dataInit"] = "attachSearchControlsScript" + column.DataField; } this._jsonValues["searchoptions"] = hashtable; } if (column.Editable) { Hashtable hashtable2 = new Hashtable(); this._jsonValues["editable"] = true; if (column.EditType != EditType.TextBox) { this._jsonValues["edittype"] = this.GetEditType(column.EditType); } if (column.EditType == EditType.CheckBox) { column.EditList.Clear(); SelectListItem item2 = new SelectListItem(); item2.Value = "true:false"; column.EditList.Add(item2); } if (column.EditType == EditType.Custom) { Guard.IsNotNullOrEmpty(column.EditTypeCustomCreateElement, "JQGridColumn.EditTypeCustomCreateElement", " should be set to the name of the javascript function creating the element when EditType = EditType.Custom"); Guard.IsNotNullOrEmpty(column.EditTypeCustomGetValue, "JQGridColumn.EditTypeCustomGetValue", " should be set to the name of the javascript function getting the value from the element when EditType = EditType.Custom"); hashtable2["custom_element"] = column.EditTypeCustomCreateElement; hashtable2["custom_value"] = column.EditTypeCustomGetValue; } foreach (JQGridEditFieldAttribute attribute in column.EditFieldAttributes) { hashtable2[attribute.Name] = attribute.Value; } if ((column.EditType == EditType.DatePicker) || (column.EditType == EditType.AutoComplete)) { hashtable2["dataInit"] = "attachEditControlsScript" + column.DataField; } if (column.EditList.Count <SelectListItem>() > 0) { StringBuilder builder2 = new StringBuilder(); int num2 = 0; foreach (SelectListItem item3 in column.EditList) { builder2.AppendFormat("{0}:{1}", item3.Value, item3.Text); num2++; if (num2 < column.EditList.Count <SelectListItem>()) { builder2.Append(";"); } } hashtable2["value"] = builder2.ToString(); } if (hashtable2.Count > 0) { this._jsonValues["editoptions"] = hashtable2; } Hashtable hashtable3 = new Hashtable(); if (column.EditDialogColumnPosition != 0) { hashtable3["colpos"] = column.EditDialogColumnPosition; } if (column.EditDialogRowPosition != 0) { hashtable3["rowpos"] = column.EditDialogRowPosition; } if (!string.IsNullOrEmpty(column.EditDialogLabel)) { hashtable3["label"] = column.EditDialogLabel; } if (!string.IsNullOrEmpty(column.EditDialogFieldPrefix)) { hashtable3["elmprefix"] = column.EditDialogFieldPrefix; } if (!string.IsNullOrEmpty(column.EditDialogFieldSuffix)) { hashtable3["elmsuffix"] = column.EditDialogFieldSuffix; } if (hashtable3.Count > 0) { this._jsonValues["formoptions"] = hashtable3; } Hashtable hashtable4 = new Hashtable(); if (!column.Visible && column.Editable) { hashtable4["edithidden"] = true; } if (column.EditClientSideValidators != null) { foreach (JQGridEditClientSideValidator validator in column.EditClientSideValidators) { if (validator is DateValidator) { hashtable4["date"] = true; } if (validator is EmailValidator) { hashtable4["email"] = true; } if (validator is IntegerValidator) { hashtable4["integer"] = true; } if (validator is MaxValueValidator) { hashtable4["maxValue"] = ((MaxValueValidator)validator).MaxValue; } if (validator is MinValueValidator) { hashtable4["minValue"] = ((MinValueValidator)validator).MinValue; } if (validator is NumberValidator) { hashtable4["number"] = true; } if (validator is RequiredValidator) { hashtable4["required"] = true; } if (validator is TimeValidator) { hashtable4["time"] = true; } if (validator is UrlValidator) { hashtable4["url"] = true; } if (validator is CustomValidator) { hashtable4["custom"] = true; hashtable4["custom_func"] = ((CustomValidator)validator).ValidationFunction; } } } if (hashtable4.Count > 0) { this._jsonValues["editrules"] = hashtable4; } } }