Exemple #1
0
        public GridColumn(Expression <Func <T, TDataType> > expression, ISGrid grid)
        {
            #region Setup defaults

            EncodeEnabled   = true;
            SortEnabled     = false;
            SanitizeEnabled = true;

            Hidden = false;

            _filterWidgetTypeName = PropertiesHelper.GetUnderlyingType(typeof(TDataType)).FullName;
            _grid = grid;

            #endregion

            if (expression != null)
            {
                var expr = expression.Body as MemberExpression;
                if (expr == null)
                {
                    throw new ArgumentException(
                              string.Format("Expression '{0}' must be a member expression", expression),
                              "expression");
                }

                _constraint = expression.Compile();
                _orderers.Insert(0, new OrderByGridOrderer <T, TDataType>(expression));
                _filter = new DefaultColumnFilter <T, TDataType>(expression);
                _search = new DefaultColumnSearch <T, TDataType>(expression);
                _totals = new DefaultColumnTotals <T, TDataType>(expression);
                //Generate unique column name:
                Name  = PropertiesHelper.BuildColumnNameFromMemberExpression(expr);
                Title = Name; //Using the same name by default
            }
        }
 public FilterGridItemsProcessor(ISGrid grid, IGridFilterSettings settings)
 {
     if (settings == null)
     {
         throw new ArgumentNullException("settings");
     }
     _grid     = grid;
     _settings = settings;
 }
Exemple #3
0
 public GridCoreServer(IEnumerable <T> items, IQueryCollection query, bool renderOnlyRows,
                       string gridName, Action <IGridColumnCollection <T> > columns = null, int?pageSize = null,
                       string language = "", string pagerViewName = GridPager.DefaultPagerViewName,
                       IColumnBuilder <T> columnBuilder = null)
 {
     _source = new SGridCore <T>(items, query, renderOnlyRows, pagerViewName, columnBuilder);
     _source.RenderOptions.GridName = gridName;
     columns?.Invoke(_source.Columns);
     if (!string.IsNullOrWhiteSpace(language))
     {
         _source.Language = language;
     }
     if (pageSize.HasValue)
     {
         WithPaging(pageSize.Value);
     }
 }
        public HiddenGridColumn(Expression <Func <T, TDataType> > expression, ISGrid grid)
        {
            _grid         = grid;
            _cellRenderer = new GridHiddenCellRenderer();
            SortEnabled   = false;

            if (expression != null)
            {
                var expr = expression.Body as MemberExpression;
                if (expr == null)
                {
                    throw new ArgumentException(
                              string.Format("Expression '{0}' must be a member expression", expression),
                              "expression");
                }

                _constraint = expression.Compile();

                Name = PropertiesHelper.BuildColumnNameFromMemberExpression(expr);
            }
        }
Exemple #5
0
 public DefaultColumnCoreBuilder(ISGrid grid, IGridAnnotationsProvider annotations)
 {
     _grid        = grid;
     _annotations = annotations;
 }
Exemple #6
0
 public GridColumn(Expression <Func <T, TDataType> > expression, ISGrid grid) : this(expression, null, grid)
 {
 }
 public DefaultColumnBuilder(ISGrid grid, IGridAnnotationsProvider annotations) : base(grid, annotations)
 {
 }
Exemple #8
0
 public TotalsGridItemsProcessor(ISGrid grid)
 {
     _grid = grid;
 }
 public GridColumn(Expression <Func <T, TDataType> > expression, IComparer <TDataType> comparer, ISGrid grid)
     : base(expression, comparer, grid)
 {
 }
 public HiddenGridColumn(Expression <Func <T, TDataType> > expression, ISGrid grid) : base(expression, grid)
 {
     Hidden = true;
 }
        public IActionResult OnGet(string gridState = "")
        {
            string returnUrl = "/GridPage";

            IQueryCollection query = Request.Query;

            if (!string.IsNullOrWhiteSpace(gridState))
            {
                try
                {
                    query = new QueryCollection(StringExtensions.GetQuery(gridState));
                }
                catch (Exception)
                {
                    // do nothing, gridState was not a valid state
                }
            }

            var requestCulture = HttpContext.Features.Get <IRequestCultureFeature>();
            var locale         = requestCulture.RequestCulture.UICulture.TwoLetterISOLanguageName;

            SharedResource.Culture = requestCulture.RequestCulture.UICulture;

            var shipperList = _shippersRepository.GetAll()
                              .Select(s => new SelectItem(s.ShipperID.ToString(), s.CompanyName))
                              .ToList();

            Action <IGridColumnCollection <Order> > columns = c =>
            {
                /* Adding not mapped column, that renders body, using inline Razor html helper */
                c.Add()
                .Encoded(false)
                .Sanitized(false)
                .SetWidth(60)
                .Css("hidden-xs")     //hide on phones
                .RenderComponentAs <ButtonCellViewComponent>(returnUrl);

                /* Adding "OrderID" column: */

                c.Add(o => o.OrderID)
                .Titled(SharedResource.Number)
                .SetWidth(100);

                /* Adding "OrderDate" column: */
                c.Add(o => o.OrderDate, "OrderCustomDate")
                .Titled(SharedResource.OrderCustomDate)
                .SortInitialDirection(GridSortDirection.Descending)
                .ThenSortByDescending(o => o.OrderID)
                .SetCellCssClassesContraint(o => o.OrderDate.HasValue && o.OrderDate.Value >= DateTime.Parse("1997-01-01") ? "red" : "")
                .Format("{0:yyyy-MM-dd}")
                .SetWidth(110)
                .Max(true).Min(true);

                c.Add(o => o.ShipVia)
                .Titled("Via")
                .SetWidth(250)
                .RenderValueAs(o => o.Shipper?.CompanyName)
                .SetListFilter(shipperList);

                /* Adding "CompanyName" column: */
                c.Add(o => o.Customer.CompanyName)
                .Titled(SharedResource.CompanyName)
                .ThenSortByDescending(o => o.ShipVia)
                .ThenSortByDescending(o => o.Freight)
                .SetWidth(250)
                .SetInitialFilter(GridFilterType.StartsWith, "a")
                .SetFilterWidgetType("CustomCompanyNameFilterWidget")
                .Max(true).Min(true);

                /* Adding "ContactName" column: */
                c.Add(o => o.Customer.ContactName).Titled(SharedResource.ContactName).SetWidth(250)
                .Max(true).Min(true);

                /* Adding "Customer.Country" hidden column: */
                c.Add(o => o.Customer.Country, true);

                /* Adding "Freight" column: */
                c.Add(o => o.Freight)
                .Titled(SharedResource.Freight)
                .SetWidth(100)
                .Format("{0:F}")
                .Sum(true).Average(true).Max(true).Min(true);

                /* Adding "Vip customer" column: */
                c.Add(o => o.Customer.IsVip)
                .Titled(SharedResource.IsVip)
                .SetWidth(80)
                .Css("hidden-xs")     //hide on phones
                .RenderValueAs(o => o.Customer.IsVip ? Strings.BoolTrueLabel : Strings.BoolFalseLabel);
            };

            var server = new GridServer <Order>(_orderRepository.GetAll(), query, false, "ordersGrid",
                                                columns, 10, locale)
                         .SetRowCssClasses(item => item.Customer.IsVip ? "success" : string.Empty)
                         .Sortable()
                         .Filterable()
                         .WithMultipleFilters()
                         .Searchable(true, false)
                         .Groupable(true)
                         .ClearFiltersButton(true)
                         .Selectable(true)
                         .SetStriped(true)
                         .ChangePageSize(true)
                         .WithGridItemsCount()
                         .SetTableLayout(TableLayout.Fixed, "1000px", "400px")
                         .SetRemoveDiacritics <NorthwindDbContext>("RemoveDiacritics");

            Grid = server.Grid;

            return(Page());
        }