You can't do what you want. However, if you properly implement pagination your grid will only retrieve the current page, which shouldn't be much.
This is easy if you use an ORM like Entity Framework, since ToDataSourceResult
will change the query to include the paging, sorting and filtering options.
Something like this:
Controller
public ActionResult GetGridData([DataSourceRequest]DataSourceRequest request)
{
using (var context = new EntityFrameworkContext())
{
IQueryable<MyModel> result = context.Products.Where(w => w.Something).Select(s => new MyModel());
return Json(result.ToDataSourceResult(request));
}
}
View
@(Html.Kendo().Grid<MyModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(c => c.Name);
columns.Bound(c => c.Date);
})
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(10)
.PageSizes(new[] { 20, 50, 100 }))
.DataSource(ds => ds
.Ajax()
.Read(r => r.Action("GetGridData", "Home"))
.PageSize(20)
)
)