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

Setting data source provider in ViewModel

1 Answer 146 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 19 Jun 2014, 08:27 AM
Hello,

Seems that all posts that are remotely related to what I am experiencing are close to or more than a year old.

Once again I have the issue with the Telerik help that all code and samples are for static data sets and I find it really difficult to get samples of code that actually work in an MVVM environment.  Point in case, according to the Telerik PivotGrid help, the following code is supposed to define rows for a localdataprovider:

Telerik.Pivot.Core.PropertyGroupDescription propertyGroupDescription = new Telerik.Pivot.Core.PropertyGroupDescription();
                propertyGroupDescription.PropertyName = "Name";
                DateTimeGroupDescription dateTimeGroupDescription = new DateTimeGroupDescription();
                dateTimeGroupDescription.PropertyName = "Date";
                dateTimeGroupDescription.Step = DateTimeStep.Month;

                using (localDataProvider.DeferRefresh())
                {
                    localDataProvider.RowGroupDescriptions.Add(propertyGroupDescription);
                    localDataProvider.RowGroupDescriptions.Add(dateTimeGroupDescription);
                };

However as soon as I set the ItemsSource property to my actual collection of data, then the RowGroupDescriptions and ColumnGroupDescriptions collections are set to 0 and then nothing shows in the control.

Same if I set the ItemsSource before defining the groups, then the PropertyGroupDescriptions don't even get added to the collections.

I can't find any help on this scenario so I have posted here.

1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen Vladimirov
Telerik team
answered on 20 Jun 2014, 08:42 AM
Hi Richard,

I've prepared a sample project to demonstrate how you can define and use LocalDataSourceProvider in your ViewModel. Please note that if you add GroupDescription and you set the PropertyName to a value that doesn't exist in your DataItem, the group description will not be created. For example - if you have collection of Orders and each Order have the following properties: "Net", "Quantity", "Product", when you try adding a new PropertyGroupDescrtiption with PropertyName="Advertisement", RadPivotGrid will not create it as there's no property "Advertisement" in Order class.

Could you test the attached project and inform us if it works for you? I'm looking forward to hearing from you.

Regards,
Rosen Vladimirov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
PivotGrid
Asked by
Richard
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Share this question
or