Use different datasource with same Grid as partial view

2 posts, 0 answers
  1. Peng
    Peng avatar
    13 posts
    Member since:
    Aug 2010

    Posted 01 Feb 2017 Link to this post

    Hi There,


    I have a situation where I will have to do many same pages with the same Grid columns and functionality, but it will have a bit different dataSource I will have to read from the backend controller. Is there a way I can template the Grid itself and reuse it but be able to switch the dataSource?


    For example.


        .Columns(columns =>
            columns.Bound(c => c.ContactName).ClientTemplate(
                    @"<div class='customer-photo'
                        style='background-image: url(../content/web/Customers/#:data.CustomerID#.jpg);'></div>
                    <div class='customer-name'>#: ContactName #</div>")
            columns.Bound(c => c.ContactTitle);
            columns.Bound(c => c.CompanyName);
            columns.Bound(c => c.Country).Width(150);
        .HtmlAttributes(new { style = "height: 550px;" })
        .Pageable(pageable => pageable
        .DataSource(dataSource => dataSource
            .Read(read => read.Action("Customers_Read", "Grid"))



    I want the


    .DataSource(dataSource => dataSource
        .Read(read => read.Action("Customers_Read", "Grid"))


    Customers_Read to be switched to OldCustomers_Read

    or NewCustomers_Read

    or CustomersEtc_Read

    But I don't want to copy everything of the Grid over and over. 

    How can I do this?


    Thank You

  2. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 03 Feb 2017 Link to this post

    Hi Peng,

    You could try something like the following:
    .Read(read => read.Action(ViewData["ReadAction"].ToString(), "Grid"))

    Hope this helps.

    Best Regards,
    Konstantin Dikov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top