I am attempting to enable server-side filtering for my ASP.NET MVC Grid. I have tried every tutorial, walkthrough, and blog post I could find, but with no success.
I would like to, on page load, call out to my data source and return just the first 25 records, but alert the grid of the total record count so that it can display the appropriate number of pages. Here is my Grid Razor code:
@(Html.Kendo().Grid<
ViewModel
>().Name("MyGrid").EnableCustomBinding(true).Columns(columns =>
{
columns.Bound(c => c.FieldA);
columns.Bound(c => c.FieldB);
columns.Bound(c => c.FieldC);
columns.Bound(c => c.FieldD);
}).ClientDetailTemplateId("DetailsTemplate").HtmlAttributes(new {@class = "myClass"}).DataSource(dataSource => dataSource
.Ajax()
.Read(read => read
.Action("Data_Read", "MyController"))
).AutoBind(false).Events(events =>
{
events.DetailCollapse("setDetailIndicatorToExpand");
events.DetailExpand("setDetailIndicatorToCollapse");
events.DataBound("replaceDetailTemplateIndicatorStyle");
}).Pageable().Deferred())
This was done by following this article: http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/binding/custom-binding#configuration-Apply
I have tried many variations of this, including removing AutoBind(). As far as I can tell, part of my issue is that I am not defining what the PageSizes are; whenever I set the PageSizes value I get an error of "Uncaught TypeError: r._query is not a function".
No matter what I try, the page count is always 0.
From the server-side, I am using the PageSize and Page number from the DataSourceRequest object to pass in as parameters to my data source. I am then returning the following:
var result =
new
DataSourceResult
{
Data = myData,
Total = 300
// this is dynamic, just hardcoded here as an example
};
return
Json(result);
Can someone please assist?
Thank you.