Ejemplo n.º 1
0
        private void ApplyColumnAnnotationSettings(IGridColumn <T> column, GridColumnAttribute options)
        {
            column.Encoded(options.EncodeEnabled)
            .Sanitized(options.SanitizeEnabled)
            .Filterable(options.FilterEnabled)
            .Sortable(options.SortEnabled);

            GridSortDirection?initialDirection = options.GetInitialSortDirection();

            if (initialDirection.HasValue)
            {
                column.SortInitialDirection(initialDirection.Value);
            }

            if (!string.IsNullOrEmpty(options.FilterWidgetType))
            {
                column.SetFilterWidgetType(options.FilterWidgetType);
            }

            if (!string.IsNullOrEmpty(options.Format))
            {
                column.Format(options.Format);
            }
            if (!string.IsNullOrEmpty(options.Title))
            {
                column.Titled(options.Title);
            }
            if (!string.IsNullOrEmpty(options.Width))
            {
                column.Width = options.Width;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Enumerates through the ModelMetadata for a given type and
        /// adds columns to the Grid
        /// </summary>
        /// <param name="insertColumns"></param>
        public MetaDataGridModel(Action <ColumnBuilder <T>, ColumnRender> insertColumns, HtmlHelper html)
        {
            //To insert any custom columns the user wishes to add in front of the auto generated ones.
            //Ideally the MVCContrib Grid should allow inserting columns
            insertColumns(this.Column, ColumnRender.Before);

            var modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => null, typeof(T));

            foreach (var modelMetadataProperty in modelMetadata.Properties)
            {
                if (modelMetadataProperty.ShowForDisplay)
                {
                    bool   isSortable          = modelMetadataProperty.AdditionalValues.ContainsKey(Globals.OrderByAttributeKey);
                    string displayFormatString = modelMetadataProperty.DisplayFormatString;
                    var    expression          = CreateExpression(modelMetadataProperty, html);

                    IGridColumn <T> column = Column.For(expression)
                                             .Named(modelMetadataProperty.GetDisplayName())
                                             .Sortable(isSortable)
                                             .SetName(modelMetadataProperty.PropertyName)
                                             .Encode(false);


                    if (!string.IsNullOrEmpty(displayFormatString))
                    {
                        column.Format(displayFormatString);
                    }
                }
            }
            insertColumns(this.Column, ColumnRender.After);
        }
Ejemplo n.º 3
0
        private void ApplyColumnAnnotationSettings(IGridColumn <T> column, GridColumnAttribute options)
        {
            column.Encoded(options.EncodeEnabled)
            .Sanitized(options.SanitizeEnabled)
            .Filterable(options.FilterEnabled)
            .Sortable(options.SortEnabled);

            GridSortDirection?initialDirection = options.GetInitialSortDirection();

            if (initialDirection.HasValue)
            {
                column.SortInitialDirection(initialDirection.Value);
            }

            GridAggregateFunction?aggregateValue = options.GetAggregateFunction();

            if (aggregateValue.HasValue)
            {
                column.Aggregate(aggregateValue.Value);
            }

            if (!string.IsNullOrEmpty(options.FilterWidgetType))
            {
                column.SetFilterWidgetType(options.FilterWidgetType);
            }

            if (!string.IsNullOrEmpty(options.Format))
            {
                column.Format(options.Format);
            }
            if (!string.IsNullOrEmpty(options.Title))
            {
                column.Titled(options.Title);
            }
            if (!string.IsNullOrEmpty(options.Width))
            {
                column.Width = options.Width;
            }
            if (!string.IsNullOrEmpty(options.ToolTip))
            {
                column.ToolTip = options.ToolTip;
            }
            if (!string.IsNullOrEmpty(options.Css))
            {
                column.Css(options.Css);
            }
            if (!string.IsNullOrEmpty(options.BoolTrue))
            {
                column.BoolTrue = options.BoolTrue;
            }
            if (!string.IsNullOrEmpty(options.BoolFalse))
            {
                column.BoolFalse = options.BoolFalse;
            }
            if (!string.IsNullOrEmpty(options.AggregateFormat))
            {
                column.AggregateFormat = options.AggregateFormat;
            }
        }
Ejemplo n.º 4
0
 private void ApplyHiddenColumnAnnotationSettings(IGridColumn <T> column, GridHiddenColumnAttribute options)
 {
     column.Encoded(options.EncodeEnabled).Sanitized(options.SanitizeEnabled);
     if (!string.IsNullOrEmpty(options.Format))
     {
         column.Format(options.Format);
     }
 }
Ejemplo n.º 5
0
        private IGridColumn <TModel> SubstituteColumn <TModel>()
        {
            IGridColumn <TModel> column = Substitute.For <IGridColumn <TModel> >();

            column.RenderValueAs(Arg.Any <Func <TModel, String> >()).Returns(column);
            column.Sanitized(Arg.Any <Boolean>()).Returns(column);
            column.Encoded(Arg.Any <Boolean>()).Returns(column);
            column.Format(Arg.Any <String>()).Returns(column);
            column.Titled(Arg.Any <String>()).Returns(column);
            column.Css(Arg.Any <String>()).Returns(column);

            return(column);
        }