private static JqGridColumnModel CreateJqGridColumnModel(ModelMetadata columnMetadata) { JqGridColumnModel columnModel = new JqGridColumnModel(columnMetadata.PropertyName); TimestampAttribute timeStampAttribute = null; JqGridColumnLayoutAttribute jqGridColumnLayoutAttribute = null; JqGridColumnSortableAttribute jqGridColumnSortableAttribute = null; JqGridColumnFormatterAttribute jqGridColumnFormatterAttribute = null; JqGridColumnSummaryAttribute jqGridColumnSummaryAttribute = null; foreach (Attribute customAttribute in columnMetadata.ContainerType.GetProperty(columnMetadata.PropertyName).GetCustomAttributes(true)) { timeStampAttribute = (customAttribute as TimestampAttribute) ?? timeStampAttribute; jqGridColumnLayoutAttribute = (customAttribute as JqGridColumnLayoutAttribute) ?? jqGridColumnLayoutAttribute; jqGridColumnSortableAttribute = (customAttribute as JqGridColumnSortableAttribute) ?? jqGridColumnSortableAttribute; jqGridColumnFormatterAttribute = (customAttribute as JqGridColumnFormatterAttribute) ?? jqGridColumnFormatterAttribute; jqGridColumnSummaryAttribute = (customAttribute as JqGridColumnSummaryAttribute) ?? jqGridColumnSummaryAttribute; } if (timeStampAttribute != null) { } else { columnModel = SetLayoutOptions(columnModel, jqGridColumnLayoutAttribute); columnModel = SetSortOptions(columnModel, jqGridColumnSortableAttribute); columnModel = SetFormatterOptions(columnModel, jqGridColumnFormatterAttribute); columnModel = SetSummaryOptions(columnModel, jqGridColumnSummaryAttribute); } return(columnModel); }
private static JqGridColumnModel CreateJqGridColumnModel(ModelMetadata columnMetadata, IUrlHelper urlHelper) { JqGridColumnModel columnModel = new JqGridColumnModel(columnMetadata.PropertyName); TimestampAttribute timeStampAttribute = null; RangeAttribute rangeAttribute = null; RequiredAttribute requiredAttribute = null; JqGridColumnLayoutAttribute jqGridColumnLayoutAttribute = null; JqGridColumnSortableAttribute jqGridColumnSortableAttribute = null; JqGridColumnFormatterAttribute jqGridColumnFormatterAttribute = null; JqGridColumnSearchableAttribute jqGridColumnSearchableAttribute = null; JqGridColumnEditableAttribute jqGridColumnEditableAttribute = null; JqGridColumnSummaryAttribute jqGridColumnSummaryAttribute = null; JqGridColumnMappingAttribute jqGridColumnMappingAttribute = null; foreach (Attribute customAttribute in columnMetadata.ContainerType.GetProperty(columnMetadata.PropertyName).GetCustomAttributes(true)) { timeStampAttribute = (customAttribute as TimestampAttribute) ?? timeStampAttribute; rangeAttribute = (customAttribute as RangeAttribute) ?? rangeAttribute; requiredAttribute = (customAttribute as RequiredAttribute) ?? requiredAttribute; jqGridColumnLayoutAttribute = (customAttribute as JqGridColumnLayoutAttribute) ?? jqGridColumnLayoutAttribute; jqGridColumnSortableAttribute = (customAttribute as JqGridColumnSortableAttribute) ?? jqGridColumnSortableAttribute; jqGridColumnFormatterAttribute = (customAttribute as JqGridColumnFormatterAttribute) ?? jqGridColumnFormatterAttribute; jqGridColumnSearchableAttribute = (customAttribute as JqGridColumnSearchableAttribute) ?? jqGridColumnSearchableAttribute; jqGridColumnEditableAttribute = (customAttribute as JqGridColumnEditableAttribute) ?? jqGridColumnEditableAttribute; jqGridColumnSummaryAttribute = (customAttribute as JqGridColumnSummaryAttribute) ?? jqGridColumnSummaryAttribute; jqGridColumnMappingAttribute = (customAttribute as JqGridColumnMappingAttribute) ?? jqGridColumnMappingAttribute; } if (timeStampAttribute != null) { columnModel.Editable = true; columnModel.Hidden = true; } else { columnModel = SetLayoutOptions(columnModel, jqGridColumnLayoutAttribute); columnModel = SetSortOptions(columnModel, jqGridColumnSortableAttribute); columnModel = SetFormatterOptions(columnModel, jqGridColumnFormatterAttribute); columnModel = SetSearchOptions(columnModel, urlHelper, columnMetadata.ModelType, jqGridColumnSearchableAttribute, rangeAttribute); columnModel = SetEditOptions(columnModel, urlHelper, columnMetadata.ModelType, jqGridColumnEditableAttribute, rangeAttribute, requiredAttribute); columnModel = SetDatePickerDateFormatFromFormatter(columnModel, jqGridColumnFormatterAttribute); columnModel = SetSummaryOptions(columnModel, jqGridColumnSummaryAttribute); columnModel = SetMappingOptions(columnModel, jqGridColumnMappingAttribute); } return(columnModel); }
private static JqGridSubgridColumnModel CreateJqGridSubgridColumnModel(ModelMetadata columnMetadata) { JqGridAlignments alignment = JqGridOptionsDefaults.ColumnModel.Alignment; int width = JqGridOptionsDefaults.ColumnModel.Width; foreach (Attribute customAttribute in columnMetadata.ContainerType.GetProperty(columnMetadata.PropertyName).GetCustomAttributes(true)) { JqGridColumnLayoutAttribute jqGridColumnLayoutAttribute = (customAttribute as JqGridColumnLayoutAttribute); if (jqGridColumnLayoutAttribute != null) { alignment = jqGridColumnLayoutAttribute.Alignment; width = jqGridColumnLayoutAttribute.Width; break; } } return(new JqGridSubgridColumnModel(columnMetadata.GetDisplayName(), alignment, width, columnMetadata.PropertyName)); }
/// <summary> /// Initializes a new instance of the JqGridSubgridModel class. /// </summary> public JqGridSubgridModel() { ModelMetadata modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(TModel)); foreach (ModelMetadata propertyMetadata in modelMetadata.Properties.Where(p => p.ShowForDisplay && !p.IsComplexType)) { IEnumerable <object> customAttributes = propertyMetadata.ContainerType.GetProperty(propertyMetadata.PropertyName).GetCustomAttributes(true).AsEnumerable(); JqGridColumnLayoutAttribute columnLayoutAttribute = customAttributes.OfType <JqGridColumnLayoutAttribute>().FirstOrDefault(); if (columnLayoutAttribute != null) { ColumnsAlignments.Add(columnLayoutAttribute.Alignment); ColumnsWidths.Add(columnLayoutAttribute.Width); } else { ColumnsAlignments.Add(JqGridAlignments.Left); ColumnsWidths.Add(150); } ColumnsNames.Add(propertyMetadata.GetDisplayName()); } }
private static JqGridColumnModel SetLayoutOptions(JqGridColumnModel columnModel, JqGridColumnLayoutAttribute jqGridColumnLayoutAttribute) { if (jqGridColumnLayoutAttribute != null) { columnModel.Alignment = jqGridColumnLayoutAttribute.Alignment; columnModel.CellAttributes = jqGridColumnLayoutAttribute.CellAttributes; columnModel.Classes = jqGridColumnLayoutAttribute.Classes; columnModel.Fixed = jqGridColumnLayoutAttribute.Fixed; columnModel.Frozen = jqGridColumnLayoutAttribute.Frozen; columnModel.HideInDialog = jqGridColumnLayoutAttribute.HideInDialog; columnModel.Resizable = jqGridColumnLayoutAttribute.Resizable; columnModel.Title = jqGridColumnLayoutAttribute.Title; columnModel.Width = jqGridColumnLayoutAttribute.Width; columnModel.Viewable = jqGridColumnLayoutAttribute.Viewable; } return(columnModel); }