This is a migrated thread and some comments may be shown as answers.

Use different datasource with same Grid as partial view

1 Answer 185 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Peng
Top achievements
Rank 1
Peng asked on 02 Feb 2017, 01:04 AM

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.

 

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.CustomerViewModel>()
    .Name("grid")
    .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>")
          .Width(240);
        columns.Bound(c => c.ContactTitle);
        columns.Bound(c => c.CompanyName);
        columns.Bound(c => c.Country).Width(150);
    })
    .HtmlAttributes(new { style = "height: 550px;" })
    .Scrollable()
    .Groupable()
    .Sortable()
    .Pageable(pageable => pageable
        .Refresh(true)
        .PageSizes(true)
        .ButtonCount(5))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("Customers_Read", "Grid"))
        .PageSize(20)
    )
)

 

 

I want the

 

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

 

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

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 03 Feb 2017, 01:20 PM
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.
Tags
General Discussions
Asked by
Peng
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or