This is a migrated thread and some comments may be shown as answers.

Grid sorting questions

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Douglas
Top achievements
Rank 1
Douglas asked on 29 Jan 2013, 09:21 PM
Hi.  I'm pretty new to the Kendo controls so hopefully I'm just missing something obvious here.

First question: How do I apply a descending sort by default on a grid?  Here's my current grid definition but the sort (by date_time) is ascending rather than descending:

@(Html.Kendo().Grid<DSG.Support.EntityModel.Models.SolutionFeedback>()
    .Name("KBFeedbackGrid")
    .Columns(columns =>
    {
        columns.Bound("solution_id").Title("KB#");
        columns.Command(act => act.Custom("Edit"));
        columns.Bound("site_id").Title("Acc ID");
        columns.Bound("site_name").Title("Account Name");
        columns.Bound("rating_score").Title("Rating").HtmlAttributes(new { @class = "ratingCol" });
        columns.Bound("date_time").Title("Created").Format("{0:MM/dd/yyyy HH:mm}");
        columns.Bound("comments").Title("Comment");
        columns.Bound("action_taken").Title("Action");
    })
    .DataSource(dataSource => dataSource.Ajax()
        .Read(read => read.Action("Query", "KBFeedback").Data("GetSearchCriteria"))
        .Sort(sort => sort.Add(x => x.date_time))
        )
    .Pageable()
    .Sortable(sort => sort.AllowUnsort(false).Enabled(true).SortMode(GridSortMode.SingleColumn))
)
I
Second question:  The sort option doesn't seem to be reaching the MVC action.

public JsonResult Query(DataSourceRequest request, KBFeedbackSearchCriteria query)
{
    // Here request contains the page number and page size but the Sorts collection is null
 
    int count = 42; // Get count from linq query
    IEnumerable<SolutionFeedback> results = null; // Get data from linq query
 
    return Json(new DataSourceResult() { Data = results, Total = count }, JsonRequestBehavior.AllowGet);
}
If I look at the form or add a "sort" string param to the Query function I can see the sort information being passed (e.g. "site_name-asc") but it isn't being pulled into the request object.

From another thread I found I saw a recommendation to make sure kendo.aspnetmvc.min.js is included but I checked and it is.

@Scripts.Render("~/bundles/modernizr")
<!--This bundle was moved by the Kendo UI VS Extensions for compatibility reasons-->
@Scripts.Render("~/bundles/jquery")
<!--This CSS entry was added by the Kendo UI VS Extensions for compatibility reasons-->
<link href="@Url.Content("~/Content/kendo.compatibility.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2012.3.1315/kendo.common.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2012.3.1315/kendo.dataviz.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2012.3.1315/kendo.default.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2012.3.1315/kendo.dataviz.default.min.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/kendo/2012.3.1315/jquery.min.js")"></script>
<script src="@Url.Content("~/Scripts/kendo/2012.3.1315/kendo.all.min.js")"></script>
<script src="@Url.Content("~/Scripts/kendo/2012.3.1315/kendo.aspnetmvc.min.js")"></script>
<script src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"></script>
What else should I check?

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 30 Jan 2013, 06:16 PM
Hi Douglas,

 
To set initial descending sorting you can use the Descending method:

.Sort(s => s.Add(x => x.date_time).Descending())

Regarding your second question, you should set the DataSourceRequest attribute to your request parameter to get the sorting information:
public JsonResult Query([DataSourceRequest] DataSourceRequest request, KBFeedbackSearchCriteria query)

You can find more information on this topic in the Documentation. I hope this information helps you.

Kind regards,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Douglas
Top achievements
Rank 1
answered on 30 Jan 2013, 07:40 PM
That's great, thanks.  I do try to refer to the docs but it's a lot to take in when you're first learning (especially if you're new to MVC as well...)

Works perfectly now :)
Tags
Grid
Asked by
Douglas
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Douglas
Top achievements
Rank 1
Share this question
or