Monday, June 29, 2015

Kendo Grid - Not Sorting when using DataSource Read for Binding

I had a Kendo Grid that was using server side binding, I think that is what it is called, to get the data. The problem I was having was the Sorting. The grid was marked Sortable() and appeared to be doing something, just not sorting! I found that if I added .ServerOperation(false) to the DataSource attributes this fixed the issue and it began sorting correctly. Not sure if there are any load consequences to this or not but it does work.
  1. @(Html.Kendo().Grid<UsageStatics>()
  2. .Deferred()
  3. .Name("MyGrid")
  4. .Columns(columns =>
  5. {
  6. columns.Bound(p => p.UserName).Title("User")
  7. columns.Bound(p => p.LoginDate).Title("Last Login")
  8. })
  9. .Pageable(pager => pager
  10. .Refresh(true))
  11. .Sortable(s => s.SortMode(GridSortMode.MultipleColumn).AllowUnsort(true))
  12. .Filterable()
  13. .Scrollable()
  14. .Events(e => e.DataBound("_onDataBound"))
  15. .DataSource(dataSource => dataSource
  16. .Ajax()
  17. .PageSize(200)
  18. .Events(events => events.Error("errorHandler"))
  19. .ServerOperation(false) //allows sorting...
  20. .Read(read => read.Action("GetUsers", "MyControllerName").Data("gridData"))
  21. )
  22. )

No comments:

Post a Comment