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 } })); }
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); } }
/// <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; }
/// <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; }
public IGridWithOptions <T> Sort(GridSortOptions sortOptions, string prefix) { _gridModel.SortOptions = sortOptions; _gridModel.SortPrefix = prefix; return(this); }
public IGridWithOptions <T> Sort(GridSortOptions sortOptions) { _gridModel.SortOptions = sortOptions; return(this); }