This project is read-only.

Request: Override "grid-column" and "grid-dir" Parameter Names like we can with "grid-page"

Feb 26, 2014 at 12:48 AM
Edited Feb 26, 2014 at 1:07 AM
I can't figure out how to override "grid-column" and "grid-dir".

I can:
var gridSortSettings = new QueryStringSortSettings
        ColumnQueryParameterName = "OrderBy",
        DirectionQueryParameterName = "OrderByDirection",
        ColumnName = "RequestDate",
        Direction = GridSortDirection.Descending
But QueryStringGridSettingsProvider.SortSettings has no setter.

If I implement my own IGridSettingsProvider, I can't call
headerRenderer.AddAdditionalRenderer(new QueryStringFilterColumnHeaderRenderer(_filterSettings));
headerRenderer.AddAdditionalRenderer(new QueryStringSortColumnHeaderRenderer(_sortSettings));
because QueryStringFilterColumnHeaderRenderer is an internal class.

Is there anyway to use my own Sort Column and Sort Direction query string parameter names?

Not liking having to translate in my view, as I'm doing here:
public ActionResult Index(SearchRequestsQueryString qs)
    if (!Request.QueryString.AllKeys.Any())
        return View();
        qs.OrderBy = Request.QueryString["grid-column"];
        qs.OrderByDirection = Request.QueryString["grid-dir"] == "0" ? "Asc" : "Desc";

        var vm = new SearchRequestsRepository().GetSearchRequestsViewModel(qs, 10);

        return View(vm);
Also, because "grid-column" and "grid-dir" have dashes in them, I can't use MVC Model Binding on a query string class. Because variables with a dash in them are illegal. If they weren't illegal i'd just rename my query string class variables to match the query string names so model binding could work it's magic. But I'd still much rather be able to define my own query string names
Mar 1, 2014 at 6:08 AM

Yes query string setting providing hidden under IGridSortSettings

It is not beauty, but you can cast setting to querystring providers:
                .ColumnQueryParameterName = "myparam";
Jul 27, 2014 at 11:49 PM

I've tried to implement this but can't seem to get it to work.

Could you explain exactly what I need to do to change the name of the query string parameter name?

Jul 28, 2014 at 5:44 AM

Settings is a property of Grid<T> class. You need to create derrived class:
    public class OrdersGrid : Grid<Order>
        public OrdersGrid(IQueryable<Order> items)
            : base(items)
               .ColumnQueryParameterName = "myparam";
var grid = new OrdersGrid(repository.GetAll());
return View(grid);
Jul 28, 2014 at 6:49 PM

Thanks for your reply

I think i've done everything right but im still missing something becuase im getting a compile error

Compiler Error Message: CS0411: The type arguments for method 'GridMvc.Html.GridExtensions.Grid<T>(System.Web.Mvc.HtmlHelper, System.Collections.Generic.IEnumerable<T>)' cannot be inferred from the usage. Try specifying the type arguments explicit

@model MyApp.Areas.Admin.Models.UsersModel

@Html.Grid(Model).Columns(columns =>...

public ActionResult Index()
        var grid = new MyUsersGrid(db.GetAllUsers());
        return View(grid );
public class MyUsersGrid : Grid<UsersModel>
    public MyUsersGrid (IQueryable<UsersModel> users)
        : base(users)
           .ColumnQueryParameterName = "myparam";
public IQueryable<UsersModel> GetAllUsers()
        return collection.AsQueryable<UsersModel>();
Jul 28, 2014 at 7:28 PM
Edited Jul 28, 2014 at 10:26 PM
I changed to @model MyApp.Areas.Admin.Models.UsersModelGrid

And now it works.

Is there a way i can turn

UserManager?column=UserID&dir=1 into UserManager/UserID/1

Also where can i change the 'grid-page'?