Example #01: Custom ajax binding1. Here we can send our view to the client, no need to pass any data yet.
public ActionResult CustomAjaxBinding()
{
return View();
}
2. And then send the data through ajax requests.
[ApplyTransaction, GridAction(EnableCustomBinding = true)]
public ActionResult CustomAjaxBindingData(GridCommand command)
{
// We have to use another query to count because of an issue in NHibernate:
// (currently fixed in the unreleased version 3.3.0)
// https://nhibernate.jira.com/browse/NH-2846
var query = NHibernateHelper.CurrentSession.Query<Product>().Fetch(x => x.Category);
var queryToCount = NHibernateHelper.CurrentSession.Query<Product>();
var gridQueryProvider = new GridQueryProvider(query, queryToCount);
var gridHelper =
new GridCustomBindingHelper<Product, ProductModel>(command, gridQueryProvider);
var gridModel = gridHelper.BuildGridModel();
return View(gridModel);
}
3. Finaly, the Grid configuration
@(Html.Telerik().Grid<ProductModel>().Name("Grid")
.Columns(columns =>
{
columns.Bound(d => d.ProductID).Width(80);
columns.Bound(d => d.ProductName);
columns.Bound(d => d.QuantityPerUnit);
columns.Bound(d => d.Category.CategoryName).Title("Category");
})
.EnableCustomBinding(true).Sortable().Filterable().Groupable()
.Pageable(x => x.PageSize(15))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select<ExamplesController>(ctr => ctr.CustomAjaxBindingData(null))))