How sorted?

Feb 18, 2013 at 6:18 AM
Hi!
I write :
Columns.Add(x => x.Start).Sortable(true).Titled("Начало").SetWidth(80);

But, when I click on head this column, page is reload and nothing. What I must write that sort will worked?
Coordinator
Feb 18, 2013 at 6:42 AM
Can you provide more information about your model class? Which type your Start property? How you use this code?
Feb 18, 2013 at 6:57 AM
model class :
public Event(IQueryable<EventsReportFields> items) : base(items)
    {
        var number = Columns.Add(x => x.Number).Sortable(true).Titled("Номер").SetWidth(80);

        number.IsSorted = true;
        number.Direction = GridSortDirection.Ascending;

        Columns.Add(x => x.Start).Sortable(true).Titled("Начало").SetWidth(80);
        Columns.Add(x => x.End).Titled("Конец").SetWidth(80);
        Columns.Add(x => x.DurationTick).Sortable(true).Titled("Длительность").SetWidth(80); 
        Columns.Add(x => x.EventType).Titled("Шаблон").SetWidth(80);
        Columns.Add(x => x.EventName).Titled("Событие").SetWidth(80);
        Columns.Add(x => x.Mileage).Sortable(true).Titled("Пробег").SetWidth(80);

       EnablePaging = true;
        Pager.PageSize = 20;
    }
Start property is DateTime

Use :
in View : @Html.Partial("_Grid", Model)
in Controll :
    public ActionResult Report()
    {
        var data = (Event) TempData["report"];
        return View(data);
    }
in result table is built, but sorting not worked
Coordinator
Feb 18, 2013 at 8:05 AM
It seems ok. What about other sortable fields (Number, DurationTick) ? Is sorting works for them?
What version of the grid you are using?

Can you provide code of your EventsReportFields class?

By the way: you can set initial direction of the column using SortInitialDirection method:
Columns.Add(x => x.Number).Sortable(true).SortInitialDirection(GridSortDirection.Ascending).Titled("Номер").SetWidth(80)
Feb 18, 2013 at 8:48 AM
All sortable fields not working.
Version - 2.2.1

public class EventsReportFields
{
    public string Number{ get; set; }
    public long EventTypeID { get; set; }
    public string EventType { get; set; }
    public string EventName { get; set; }
    public DateTime Start { get; set; }
    public DateTime End { get; set; }
    public long DurationTick { get; set; }
    public double Mileage { get; set; }
}

May be I must write some additional code?
Coordinator
Feb 18, 2013 at 8:59 AM
It looks all is fine.
Can you provide the link, which you are redirected after click on the grid header?

The repository has sample project that demostrates sorting and filtering, you can see it, may be it helps to understand why sorting not worked.

Also you can try to render Grid.Mvc by Html.Helper (without using custom grid class - Event in your case)
@Html.Grid(Model.ItemsForGrid).Columns(columns =>
{
    columns.Add(x => x.Number)
        .SortInitialDirection(GridSortDirection.Ascending)
        .Sortable(true)
        .Titled("Номер")
        .SetWidth(80);


    columns.Add(x => x.Start)
        .Sortable(true)
        .Titled("Начало")
        .SetWidth(80);

    columns.Add(x => x.End)
        .Titled("Конец")
        .SetWidth(80);

    columns.Add(x => x.DurationTick)
        .Sortable(true)
        .Titled("Длительность")
        .SetWidth(80);

    columns.Add(x => x.EventType)
        .Titled("Шаблон")
        .SetWidth(80);

    columns.Add(x => x.EventName)
        .Titled("Событие")
        .SetWidth(80);

    columns.Add(x => x.Mileage)
           .Sortable(true)
           .Titled("Пробег")
           .SetWidth(80);

}).WithPaging(30)
Feb 18, 2013 at 9:25 AM
Start adress http://localhost:18040/Home/Report

after click : http://localhost:18040/Home/Report?grid-column=Number&grid-dir=1

where I may found example?
Coordinator
Feb 18, 2013 at 9:30 AM
I see that you get grid object from TempData, where and how you are building it?

You can download last source code release at - http://gridmvc.codeplex.com/SourceControl/changeset/22731
Feb 18, 2013 at 9:35 AM
this is Event type object. from main form
Coordinator
Feb 18, 2013 at 9:38 AM
I think the problem hides in this point. Can you try ti create Event object in controller action, like
public ActionResult Report()
    {
        var items = /* GET ITEMS TO DISPLAY */
        var data = new Event(items);
        return View(data);
    }
Feb 18, 2013 at 9:45 AM
when I click on head column for sorting my table not create. May be in this reason?
Coordinator
Feb 18, 2013 at 9:49 AM
I think yes, you need to construct grid object on each request
Feb 20, 2013 at 6:27 AM
You are right! All worked!

Thanks