SortInitialDirection and Paging

Mar 14, 2013 at 12:18 AM
Hello,

I may have missed something, but when I use SortInitialDirection and WithPaging then click on another page, I don't see the grid-column or grid-dir being set. This only happens on the initial page without a column header clicked. If I click the column header, then click another page they are set correctly.
@Html.Grid(Model).Columns(columns =>
{
    columns.Add(m => m.Name).Titled("Name")
        .SortInitialDirection(GridSortDirection.Ascending)
        .Sortable(true)
        .Sanitized(false)
        .Encoded(false)
        .RenderValueAs(m => Html.ActionLink(m.Name, "Edit", "MyController", new { id = m.ID }, null).ToHtmlString());
    columns.Add(m => m.Expiry).Titled("Expiry");
}).WithPaging(20)
Thanks!
Coordinator
Mar 14, 2013 at 4:30 AM
Hello,

Method SortInitialDirection don't make sorting of your collection. It used when you want to tell, that your initial collection already sorted by this column.

For example you can sort collection in your controller:
var items = _collection.GetAll().OrderBy(m=>m.Name);
return View(items);
And tell to the grid, that collection already sorted by this column:
@Html.Grid(Model).Columns(columns =>
{
    columns.Add(m => m.Name).Titled("Name")
        .SortInitialDirection(GridSortDirection.Ascending);
}).WithPaging(20)
Mar 14, 2013 at 5:18 PM
Ahh I see. Thanks!

PS. Excellent work on the Grid control, keep it up!