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

[Solved] Render grid with dynamic view

5 Answers 47 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.
thomas
Top achievements
Rank 1
thomas asked on 13 Jun 2011, 11:27 PM
I have a view which the user puts together themselfs.  So my view model looks something like this:

 public class DynamicListViewModel
    {
        public DynamicListViewModel()
        {
            DyanmicViewModels = new List<DynamicViewModel> {new DynamicViewModel()};
        }

        public IList<DynamicViewModel> DyanmicViewModels { get; set; }
        
    }

 public class DynamicViewModel
    {
        public DynamicViewModel()
        {
            ColumnValues = new Dictionary<string, string> {{"Key1", "Value1"}, {"Key2", "Value2"}, {"Key3", "Value3"}};
        }

        public IDictionary<string, string> ColumnValues { get; set; }
    }

My question is how do ii build up a grid that takes advantage of sortting, paging, filtering etc.  I do not have columns which i can bind to.

Any assisstance would be appreciated.

5 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 14 Jun 2011, 06:53 AM
Hi Thomas,

You can use autogenerated columns:

http://demos.telerik.com/aspnet-mvc/grid/autogeneratecolumns

All the best,
Dimo
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
thomas
Top achievements
Rank 1
answered on 14 Jun 2011, 07:48 AM
Hi,

Thank for you for the quick response, however i don't understand how autogenerated columns will help me in this case.  Could you provide a sample please?

Also could you explain the difference between using AutoGenerated columns and me building up a dataview and using that as the Grids datasource.

Cheers,
Thomas
0
Atanas Korchev
Telerik team
answered on 14 Jun 2011, 07:52 AM
Hi thomas,

If you don't specify the columns the grid will create a column for every public property of the model which is bindable (of primitive type).

 The autogenerated columns example is the only one which we currently have. You can just try binding the grid without setting the columns and see how it goes from there.

Regards,
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
thomas
Top achievements
Rank 1
answered on 14 Jun 2011, 11:40 AM
public class DynamicListViewModel
    {
        public DynamicListViewModel()
        {
            DyanmicViewModels = new List<DynamicViewModel> {new DynamicViewModel()};
        }

        public IList<DynamicViewModel> DyanmicViewModels { get; set; }
        
    }

 public class DynamicViewModel
    {
        public DynamicViewModel()
        {
            ColumnValues = new Dictionary<string, string> {{"Key1", "Value1"}, {"Key2", "Value2"}, {"Key3", "Value3"}};
        }

        public IDictionary<string, string> ColumnValues { get; set; }
    }

The Grid will be trying to auto generate a column for DyanmicViewModels which is not a primitive type.  So i don't understand how the AutoGenerate feature helps me in this case.
0
Atanas Korchev
Telerik team
answered on 14 Jun 2011, 12:01 PM
Hi thomas,

 Indeed the autogenerated columns will no be of help here. I am afraid the Telerik MVC Grid does not support your view model.  It needs a member expression in order to get access to the bound field. This is required for sorting, filtering and grouping.

Regards,
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
Tags
Grid
Asked by
thomas
Top achievements
Rank 1
Answers by
Dimo
Telerik team
thomas
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or