Iraj
Iraj

Reputation: 1522

Kendo datagrid not sending sort field parameter to server (Controller in MVC)

I have a kendo datagrid . The paging features work perfectly. However, the control keeps sending a blank sort field parameter when clicking a column heading to sort the data.

Interestingly, the control still sends the sort direction, just not the field name.

I’ve set sortable to true, DataSource, set serverPaging to true, and defined data types for each column. Is there anything else I am missing?

Index.cshtml :

    <div class="k-rtl">

    @(Html.Kendo().Grid<KendoSample.Models.Person>()
   .Name("grid")
   .Columns(columns =>
    {
        columns.Bound(p => p.PersonId).Title("Person Code").Width(100).Sortable(true);
        columns.Bound(p => p.Name).Title("Person Name").Width(200).Sortable(true);
        columns.Bound(p => p.Family).Title("Person Family").Sortable(true);
    })
.Pageable()
.ToolBar(s => { s.Create(); })
.Scrollable()
.Sortable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
    .Ajax()
                            .Sort(sort =>
                            {
                                sort.Add(p => p.Name);
                                sort.Add(x => x.Family);
                            })
                            .Model(c => c.Id(p => p.PersonId))
                            .Create(c => c.Action("Read", "Home"))
                            .ServerOperation(true)
    .PageSize(8)
    .Read(read => read.Action("EditingPopup_read", "Home"))
 ).Sortable(c => c.AllowUnsort(false).SortMode(GridSortMode.SingleColumn))
 .Resizable(resize => resize.Columns(true))
 )

</div>

Controller :

        public ActionResult EditingPopup_read ([DataSourceRequest]DataSourceRequest request)
    {
        return Json(GetCustomers().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);

    }

Param in firebug :

page    1
pageSize    8
skip    0
sort[0][dir]    asc
sort[0][field]  Name
take    8

But in Controller , sorts is null. please help me.

Upvotes: 2

Views: 4534

Answers (2)

Mahib
Mahib

Reputation: 4063

Your sorting should be in Sortable(), isn't it? Please check their official demo.

http://demos.kendoui.com/web/grid/sorting.html

Upvotes: 0

Iraj
Iraj

Reputation: 1522

Thanks. I'm resolve this issue by include kendo.aspnetmvc.min.js . see link

Upvotes: 2

Related Questions