Esempio n. 1
0
        private RouteValueDictionary CreateRouteValuesForSortOptions(GridSortOptions sortOptions, string prefix)
        {
            if (string.IsNullOrEmpty(prefix))
            {
                return(new RouteValueDictionary(sortOptions));
            }

            //There must be a nice way to do this...
            return(new RouteValueDictionary(new Dictionary <string, object>()
            {
                { prefix + "." + "Column", sortOptions.Column },
                { prefix + "." + "Direction", sortOptions.Direction }
            }));
        }
Esempio n. 2
0
        protected override void RenderHeaderText(GridColumn <T> column)
        {
            if (IsSortingEnabled && column.Sortable)
            {
                string sortColumnName = GenerateSortColumnName(column);

                bool isSortedByThisColumn = GridModel.SortOptions.Column == sortColumnName;

                var sortOptions = new GridSortOptions
                {
                    Column = sortColumnName
                };

                if (isSortedByThisColumn)
                {
                    sortOptions.Direction = (GridModel.SortOptions.Direction == SortDirection.Ascending)
                                                ? SortDirection.Descending
                                                : SortDirection.Ascending;
                }
                else                 //default sort order
                {
                    sortOptions.Direction = column.InitialDirection ?? GridModel.SortOptions.Direction;
                }

                var routeValues = CreateRouteValuesForSortOptions(sortOptions, GridModel.SortPrefix);

                //Re-add existing querystring
                foreach (var key in Context.RequestContext.HttpContext.Request.QueryString.AllKeys.Where(key => key != null))
                {
                    if (!routeValues.ContainsKey(key))
                    {
                        routeValues[key] = Context.RequestContext.HttpContext.Request.QueryString[key];
                    }
                }

                var link = HtmlHelper.GenerateLink(Context.RequestContext, RouteTable.Routes, column.DisplayName, null, null, null, routeValues, null);
                RenderText(link);
            }
            else
            {
                base.RenderHeaderText(column);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Specifies that the grid is currently being sorted by the specified column in a particular direction.
 /// This overload allows you to specify a prefix.
 /// </summary>
 public void Sort(GridSortOptions sortOptions, string prefix)
 {
     _sortOptions = sortOptions;
     _sortPrefix  = prefix;
 }
Esempio n. 4
0
 /// <summary>
 /// Secifies that the grid is currently being sorted by the specified column in a particular direction.
 /// </summary>
 public void Sort(GridSortOptions sortOptions)
 {
     _sortOptions = sortOptions;
 }
Esempio n. 5
0
 public IGridWithOptions <T> Sort(GridSortOptions sortOptions, string prefix)
 {
     _gridModel.SortOptions = sortOptions;
     _gridModel.SortPrefix  = prefix;
     return(this);
 }
Esempio n. 6
0
 public IGridWithOptions <T> Sort(GridSortOptions sortOptions)
 {
     _gridModel.SortOptions = sortOptions;
     return(this);
 }