This project is read-only.
Example #02: Custom server binding

1. We must enter the name of the grid, otherwise it will not work.
[ApplyTransaction, GridAction(GridName = "Grid")]
public ActionResult CustomServerBinding(GridCommand command)
    // Telerik custom server binding demo: 

    // We have to inform the pageSize here, since in the first call, 
    // the GridCommand is not correctly initialized, and dont forget to
    // set it in the grid too.
    command.PageSize = 15; // Please put the same pageSize as is in the view

    // We have to use another query to count because of an issue in NHibernate:
    // (currently fixed in the unreleased version 3.3.0)
    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();

    ViewBag.Total = gridModel.Total;
    ViewBag.Data = gridModel.Data;

    return View();
2. Finaly, the Grid configuration
        .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");
        .DataBinding(dataBinding => dataBinding.Server()
        .Select<ExamplesController>(ctr => ctr.CustomServerBinding(null)))
        .Pageable(settings => settings.Total((int)ViewBag.Total)
        .PageSize(15)/* We have to inform the pageSize in the control too.*/)

Last edited Feb 28, 2012 at 12:11 AM by Luis_Fernando, version 2


No comments yet.