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:
[HttpGet]
public ActionResult Index(SearchRequestsQueryString qs)
{
    if (!Request.QueryString.AllKeys.Any())
    {
        return View();
    }
    else
    {
        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
Hi,

Yes query string setting providing hidden under IGridSortSettings

It is not beauty, but you can cast setting to querystring providers:
 ((QueryStringSortSettings)((QueryStringGridSettingsProvider)grid.Settings).SortSettings)
                .ColumnQueryParameterName = "myparam";
Jul 27, 2014 at 11:49 PM
Hi,

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?

Thanks
Jul 28, 2014 at 5:44 AM
Hi,

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)
        {
            ((QueryStringSortSettings)((QueryStringGridSettingsProvider)Settings).SortSettings)
               .ColumnQueryParameterName = "myparam";
        }
    }
controller:
var grid = new OrdersGrid(repository.GetAll());
return View(grid);
view:
@Html.Grid(Model)....
Jul 28, 2014 at 6:49 PM
Hi

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

index.cshtml
@model MyApp.Areas.Admin.Models.UsersModel

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

Controller
public ActionResult Index()
    {
        var grid = new MyUsersGrid(db.GetAllUsers());
        return View(grid );
    }
Model
public class MyUsersGrid : Grid<UsersModel>
{
    public MyUsersGrid (IQueryable<UsersModel> users)
        : base(users)
    {
        ((QueryStringSortSettings)((QueryStringGridSettingsProvider)Settings).SortSettings)
           .ColumnQueryParameterName = "myparam";
    }
}
public IQueryable<UsersModel> GetAllUsers()
    {
        return collection.AsQueryable<UsersModel>();
    }
Thanks
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'?