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

Dynamic Multipl Column Group Titles

5 Answers 372 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jako
Top achievements
Rank 1
Jako asked on 15 Dec 2014, 01:34 PM
Hello

I was wondering how I can achieve dynamic multiple column headers. Currently I have a product followed by six columns , each a pair of Quantity and Price for past three years from selected year. I wish to group each Quantity & Price of each year under a title of the year . See example.

Before the update with multiple headers I as injecting a <tr> rows with javascript after the first table element, but this doesnt export with grid.

Help much appreciated

columns.Group(group => group
.Title("Contact Info") ****** DYNAMIC HOW **** ????
.Columns(info => {
info.Bound(x => x.ContactTitle).Width(200);
info.Bound(x => x.ContactName).Width(200);
info.Group(g => g.Title("Location")
.Columns(location =>
{
location.Bound(c => c.Country).Width(200);
location.Bound(c => c.City).Width(200);
})
);
info.Bound(x => x.Phone);
})
);

5 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 17 Dec 2014, 08:37 AM
Hi Jako,

You can use a loop to create the appropriate column groups similar to the following:

for (var idx = 0; idx < 3; idx++)
{
    columns.Group(group => group
        .Title(DateTime.Now.AddYears(idx).ToString("yyyy"))
        .Columns(info =>
        {
            info.Bound(x => x.ContactTitle).Width(200);
            info.Bound(x => x.ContactName).Width(200);
            info.Group(g => g.Title("Location")
                .Columns(location =>
                {
                    location.Bound(c => c.Country).Width(200);
                    location.Bound(c => c.City).Width(200);
                })
            );
            info.Bound(x => x.Phone);
        })
    );
}



Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ali
Top achievements
Rank 1
answered on 28 Apr 2015, 06:42 AM
Can we get a complete working sample project for this?? Or more details? We have similar requirement, but year has to be picked from database..
0
Rosen
Telerik team
answered on 29 Apr 2015, 08:19 AM
Hi Roohul,

I'm afraid that we do not have such example available. 
The snippet in question creates 3 column groups, one for each sequential year, where the each group title is the year.

If you want to create multiple column groups base on the array of years loaded from the database. You will need to store them in a separate array, for example attached to the ViewModel, iterate the array and construct the column definition. For example:

foreach (var year in (string[])ViewBag.Years)
{
    columns.Group(group => group
        .Title(year)
        .Columns(info =>
        {
           //.... bound column declaration
        })
    );
}


Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
harmit
Top achievements
Rank 1
answered on 02 May 2016, 10:40 AM
how to bind column data dynamically with respect to title?
0
Rosen
Telerik team
answered on 03 May 2016, 06:44 AM

Hello harmit,

I'm afraid I could not understand your question. Could you please clarify? How it differs from the scenario discussed in this thread so far?

 

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Jako
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Ali
Top achievements
Rank 1
harmit
Top achievements
Rank 1
Share this question
or