private static 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(JsonConvert.SerializeObject(array)); }
private static string ConstructLinqFilterExpression(JQGrid grid, Util.SearchArguments args) { JQGridColumn jQGridColumn = grid.Columns.Find((JQGridColumn c) => c.DataField == args.SearchColumn); 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)) { DateTime dateTime = DateTime.Parse(args.SearchString); string str = string.Format("({0},{1},{2})", dateTime.Year, dateTime.Month, dateTime.Day); filterExpressionCompare = "{0} {1} DateTime" + str; } string str2 = string.Format("{0} != null AND ", args.SearchColumn); return(str2 + Util.GetLinqExpression(filterExpressionCompare, args, jQGridColumn.SearchCaseSensitive, jQGridColumn.DataType)); }
public static JQGridColumn GetGridColumn(GridColumnAttribute attribute, PropertyInfo prop) { JQGridColumn result = new JQGridColumn(); result.DataField = (string.IsNullOrEmpty(attribute.DataField)) ? prop.Name : attribute.DataField; result.Visible = attribute.Visible; result.HeaderText = (string.IsNullOrEmpty(attribute.HeaderText)) ? prop.Name : attribute.HeaderText; result.DataFormatString = attribute.DataFormatString; result.Fixed = attribute.Fixed; result.Width = attribute.Width; result.Sortable = attribute.Sortable; result.Frozen = attribute.Frozen; result.Resizable = attribute.Resizable; result.Editable = attribute.Editable; result.EditType = attribute.EditType; result.EditTypeCustomCreateElement = attribute.EditTypeCustomCreateElement; result.EditTypeCustomGetValue = attribute.EditTypeCustomGetValue; result.EditorControlID = attribute.EditorControlID; result.SearchType = attribute.SearchType; result.SearchControlID = attribute.SearchControlID; result.DataType = attribute.DataType ?? prop.PropertyType; result.SearchCaseSensitive = attribute.SearchCaseSensitive; result.EditDialogColumnPosition = attribute.EditDialogColumnPosition; result.EditDialogRowPosition = attribute.EditDialogRowPosition; result.EditDialogLabel = attribute.EditDialogLabel; result.EditDialogFieldPrefix = attribute.EditDialogFieldPrefix; result.EditDialogFieldSuffix = attribute.EditDialogFieldSuffix; result.EditActionIconsColumn = attribute.EditActionIconsColumn; result.TextAlign = attribute.TextAlign; result.Searchable = attribute.Searchable; result.HtmlEncode = attribute.HtmlEncode; result.HtmlEncodeFormatString = attribute.HtmlEncodeFormatString; result.ConvertEmptyStringToNull = attribute.ConvertEmptyStringToNull; result.NullDisplayText = attribute.NullDisplayText; result.SearchToolBarOperation = attribute.SearchToolBarOperation; result.FooterValue = attribute.FooterValue; result.CssClass = attribute.CssClass; result.Width = attribute.Width; result.GroupTemplate = attribute.GroupTemplate; return(result); }
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); }
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; } 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"; } if (this._grid.TreeGridSettings.Enabled && column.DataType != null) { if (column.DataType == typeof(string)) { this._jsonValues["sorttype"] = "string"; } if (column.DataType == typeof(int)) { this._jsonValues["sorttype"] = "int"; } if (column.DataType == typeof(float) || column.DataType == typeof(decimal)) { this._jsonValues["sorttype"] = "float"; } if (column.DataType == typeof(DateTime)) { this._jsonValues["sorttype"] = "date"; } } 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) { hashtable["dataInit"] = "attachSearchControlsScript" + column.DataField; } if (column.SearchOptions.Count > 0) { hashtable["sopt"] = this.GetSearchOptionsArray(column.SearchOptions); } this._jsonValues["searchoptions"] = hashtable; } if (column.Editable) { Hashtable hashtable2 = new Hashtable(); 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(); List <SelectListItem> arg_526_0 = column.EditList; SelectListItem selectListItem = new SelectListItem(); selectListItem.Value = "true:false"; arg_526_0.Add(selectListItem); } 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.AutoComplete) { hashtable2["dataInit"] = "attachEditControlsScript" + column.DataField; } 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 (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 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; } } }
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 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 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 JsonColModel(JQGridColumn column, JQGrid grid) : this(grid) { this.FromColumn(column); }
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; } 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"; } if (this._grid.TreeGridSettings.Enabled && column.DataType != null) { if (column.DataType == typeof(string)) { this._jsonValues["sorttype"] = "string"; } if (column.DataType == typeof(int)) { this._jsonValues["sorttype"] = "int"; } if (column.DataType == typeof(float) || column.DataType == typeof(decimal)) { this._jsonValues["sorttype"] = "float"; } if (column.DataType == typeof(DateTime)) { this._jsonValues["sorttype"] = "date"; } } 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) { hashtable["dataInit"] = "attachSearchControlsScript" + column.DataField; } if (column.SearchOptions.Count > 0) { hashtable["sopt"] = this.GetSearchOptionsArray(column.SearchOptions); } this._jsonValues["searchoptions"] = hashtable; } if (column.Editable) { Hashtable hashtable2 = new Hashtable(); 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(); List<SelectListItem> arg_526_0 = column.EditList; SelectListItem selectListItem = new SelectListItem(); selectListItem.Value = "true:false"; arg_526_0.Add(selectListItem); } 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.AutoComplete) { hashtable2["dataInit"] = "attachEditControlsScript" + column.DataField; } 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 (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 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; } } }
private static string BindValue(string DataField, object data, PropertyInfo[] properties, JQGridColumn column) { if (string.IsNullOrEmpty(DataField)) { return(""); } PropertyInfo prop; if (DataField.IndexOf('.') > -1) { int index = DataField.IndexOf('.'); string PropField = DataField.Substring(0, index); index++; string NewDataField = DataField.Substring(index, DataField.Length - index); prop = properties.Where(p => p.Name.ToLower().Equals(PropField.ToLower())).FirstOrDefault(); PropertyInfo[] NewProperties = prop.PropertyType.GetProperties(BindingFlags.Instance | BindingFlags.Public); object val = prop.GetValue(data, null); return(BindValue(NewDataField, val, NewProperties, column)); } else { prop = properties.Where(p => p.Name.ToLower().Equals(DataField.ToLower())).FirstOrDefault(); } if (prop != null) { if (data == null) { return(""); } if (prop.GetValue(data, null) != null) { object val = prop.GetValue(data, null); string text = (string.IsNullOrEmpty(column.DataFormatString) ? val.ToString() : column.FormatDataValue(val, column.HtmlEncode)); return(text); } else { return(""); } } return(""); }
internal static JsonTreeResponse PrepareJsonTreeResponse(JsonTreeResponse response, JQGrid grid, DataTable dt, IQueryable data = null) { 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 { object obj = dt.Rows[i]["tree_parent"]; string value2; if (obj is DBNull) { value2 = "null"; } else { value2 = Convert.ToString(dt.Rows[i]["tree_parent"]); } response.rows[i].Add("tree_parent", value2); } 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); }
internal static List <JQGridColumn> Parse <T>(List <JQGridColumn> cols) where T : class { PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public); //Get Key Attribute foreach (PropertyInfo prop in properties) { bool key = false; bool IsNew = false; JQGridColumn col = null; System.Object[] attributes = prop.GetCustomAttributes(true); foreach (object attr in attributes) { //if ((attr as Attribute).TypeId.ToString() == "System.Data.Objects.DataClasses.EdmScalarPropertyAttribute") //{ // if ((attr as System.Data.Objects.DataClasses.EdmScalarPropertyAttribute).EntityKeyProperty == true) // col.PrimaryKey = true; //} //else if ((attr as Attribute).TypeId.ToString() == "System.ComponentModel.DataAnnotations.KeyAttribute") { key = true; if (col != null) { col.PrimaryKey = key; } } if (attr is GridColumnAttribute) { GridColumnAttribute GridAttr = (attr as GridColumnAttribute); string field = (string.IsNullOrEmpty(GridAttr.DataField)) ? prop.Name : GridAttr.DataField; col = cols.Where(m => m.DataField.Equals(field)).FirstOrDefault(); if (col == null) { col = new JQGridColumn(); col.DataField = (string.IsNullOrEmpty(GridAttr.DataField)) ? prop.Name : GridAttr.DataField; IsNew = true; } col.Visible = GridAttr.Visible; col.HeaderText = (string.IsNullOrEmpty(GridAttr.HeaderText)) ? prop.Name : GridAttr.HeaderText; col.DataType = GridAttr.DataType ?? prop.PropertyType; col.PrimaryKey = key; col.DataFormatString = GridAttr.DataFormatString; col.Fixed = GridAttr.Fixed; col.Width = GridAttr.Width; col.Sortable = GridAttr.Sortable; col.Frozen = GridAttr.Frozen; col.Resizable = GridAttr.Resizable; col.Editable = GridAttr.Editable; col.EditType = GridAttr.EditType; col.EditTypeCustomCreateElement = GridAttr.EditTypeCustomCreateElement; col.EditTypeCustomGetValue = GridAttr.EditTypeCustomGetValue; col.EditorControlID = GridAttr.EditorControlID; col.SearchType = GridAttr.SearchType; col.SearchControlID = GridAttr.SearchControlID; col.SearchCaseSensitive = GridAttr.SearchCaseSensitive; col.EditDialogColumnPosition = GridAttr.EditDialogColumnPosition; col.EditDialogRowPosition = GridAttr.EditDialogRowPosition; col.EditDialogLabel = GridAttr.EditDialogLabel; col.EditDialogFieldPrefix = GridAttr.EditDialogFieldPrefix; col.EditDialogFieldSuffix = GridAttr.EditDialogFieldSuffix; col.EditActionIconsColumn = GridAttr.EditActionIconsColumn; col.TextAlign = GridAttr.TextAlign; col.Searchable = GridAttr.Searchable; col.HtmlEncode = GridAttr.HtmlEncode; col.HtmlEncodeFormatString = GridAttr.HtmlEncodeFormatString; col.ConvertEmptyStringToNull = GridAttr.ConvertEmptyStringToNull; col.NullDisplayText = GridAttr.NullDisplayText; col.SearchToolBarOperation = GridAttr.SearchToolBarOperation; col.FooterValue = GridAttr.FooterValue; col.CssClass = GridAttr.CssClass; col.Width = GridAttr.Width; col.GroupTemplate = GridAttr.GroupTemplate; } } if (IsNew) { cols.Add(col); } } return(cols); }
internal static JQGrid <T> Parse <T>() where T : class { JQGrid <T> result = new JQGrid <T>(); result.Columns = new List <JQGridColumn>(); GridAttribute gridAttr = typeof(T).GetCustomAttributes(typeof(GridAttribute), true).FirstOrDefault() as GridAttribute; if (gridAttr != null) { result.ID = gridAttr.ID; result.AutoWidth = gridAttr.AutoWidth; result.ShrinkToFit = gridAttr.ShrinkToFit; result.DataUrl = gridAttr.DataUrl; result.EditUrl = gridAttr.EditUrl; result.ColumnReordering = gridAttr.ColumnReordering; result.RenderingMode = gridAttr.RenderingMode; result.MultiSelect = gridAttr.MultiSelect; result.MultiSelectMode = gridAttr.MultiSelectMode; result.MultiSelectKey = gridAttr.MultiSelectKey; result.Width = (gridAttr.Width == 0) ? Unit.Empty : Unit.Pixel(gridAttr.Width); result.Height = (gridAttr.Height == 0) ? Unit.Empty : Unit.Pixel(gridAttr.Height); } PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public); //Get Key Attribute foreach (PropertyInfo prop in properties) { bool key = false; bool IsNew = false; JQGridColumn col = null; System.Object[] attributes = prop.GetCustomAttributes(true); foreach (object attr in attributes) { //if ((attr as Attribute).TypeId.ToString() == "System.Data.Objects.DataClasses.EdmScalarPropertyAttribute") //{ // if ((attr as System.Data.Objects.DataClasses.EdmScalarPropertyAttribute).EntityKeyProperty == true) // col.PrimaryKey = true; //} //else if ((attr as Attribute).TypeId.ToString() == "System.ComponentModel.DataAnnotations.KeyAttribute") { key = true; if (col != null) { col.PrimaryKey = key; } } if (attr is GridColumnAttribute) { IsNew = true; GridColumnAttribute GridAttr = (attr as GridColumnAttribute); col = new JQGridColumn(); col.DataField = (string.IsNullOrEmpty(GridAttr.DataField)) ? prop.Name : GridAttr.DataField; col.Visible = GridAttr.Visible; col.HeaderText = (string.IsNullOrEmpty(GridAttr.HeaderText)) ? prop.Name : GridAttr.HeaderText; col.DataType = prop.DeclaringType; col.PrimaryKey = key; col.DataFormatString = GridAttr.DataFormatString; col.Fixed = GridAttr.Fixed; col.Width = GridAttr.Width; col.Sortable = GridAttr.Sortable; col.Frozen = GridAttr.Frozen; col.Resizable = GridAttr.Resizable; col.Editable = GridAttr.Editable; col.EditType = GridAttr.EditType; col.EditTypeCustomCreateElement = GridAttr.EditTypeCustomCreateElement; col.EditTypeCustomGetValue = GridAttr.EditTypeCustomGetValue; col.EditorControlID = GridAttr.EditorControlID; col.SearchType = GridAttr.SearchType; col.SearchControlID = GridAttr.SearchControlID; col.DataType = GridAttr.DataType; col.SearchCaseSensitive = GridAttr.SearchCaseSensitive; col.EditDialogColumnPosition = GridAttr.EditDialogColumnPosition; col.EditDialogRowPosition = GridAttr.EditDialogRowPosition; col.EditDialogLabel = GridAttr.EditDialogLabel; col.EditDialogFieldPrefix = GridAttr.EditDialogFieldPrefix; col.EditDialogFieldSuffix = GridAttr.EditDialogFieldSuffix; col.EditActionIconsColumn = GridAttr.EditActionIconsColumn; col.TextAlign = GridAttr.TextAlign; col.Searchable = GridAttr.Searchable; col.HtmlEncode = GridAttr.HtmlEncode; col.HtmlEncodeFormatString = GridAttr.HtmlEncodeFormatString; col.ConvertEmptyStringToNull = GridAttr.ConvertEmptyStringToNull; col.NullDisplayText = GridAttr.NullDisplayText; col.SearchToolBarOperation = GridAttr.SearchToolBarOperation; col.FooterValue = GridAttr.FooterValue; col.CssClass = GridAttr.CssClass; col.Width = GridAttr.Width; col.GroupTemplate = GridAttr.GroupTemplate; } } if (IsNew) { result.Columns.Add(col); } } //return cols; return(result); }