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

[Solved] Grid with a variable number of columns

4 Answers 201 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
cp
Top achievements
Rank 1
cp asked on 03 Aug 2011, 06:05 PM
Hello,
I have a grid I would like to populate via ajax that can have a variable number of columns.

For instance, the first call may return an object that has a dictionary with 5 records so my grid would need to have 6 columns, the second time the dictionary will have 8 records so my grid will have 9 columns.

Is this possible?

This is what I've tried, but none of the columns get populated:
@(Html.Telerik().Grid<Table>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(e => e.Name).Title("Object name").Width(350);
for (var i = 0; i < e.Counts.length; i++)
{
columns.Bound(e => e.Counts.ElementAt(i).Value);
}
})
.Footer(false)

This is what my Table object looks like:
public class Table
    {
        public String Name { get; set; }
        public Dictionary<String, Int64> Counts { get; set; }
    }

So what I need is to have Counts.Count + 1 number of columns and populate the columns with the Name value as well as the Values of each dictionary entry - I can change the Dictionary to a List if that would make it easier to work with.

Thanks,

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 04 Aug 2011, 07:54 AM
Hi Claudiu,

 I am afraid this is not supported by Telerik Grid for ASP.NET MVC. You cannot dynamically change the number of columns during ajax binding. This may work only in server binding if you know the required number of columns beforehand.

Your class however looks as if every single record (Table) may have different number of of columns. I am not sure how the grid should display that.

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

0
cp
Top achievements
Rank 1
answered on 04 Aug 2011, 02:18 PM
The number of dictionary records will be the same for every element. If I do a full page refresh how do I go about creating and populating the columns from these dictionaries?

Thanks,
0
Accepted
Atanas Korchev
Telerik team
answered on 04 Aug 2011, 03:40 PM
Hello Claudiu,

 You can get the first item and use the number of records in order to create the required columns. You need to use template columns though. I am sending a sample project which illustrates this idea.

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

0
cp
Top achievements
Rank 1
answered on 04 Aug 2011, 08:03 PM
Perfect, this is exactly what I needed.

Thanks!
Tags
Grid
Asked by
cp
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
cp
Top achievements
Rank 1
Share this question
or