is there any sample code for binding an arbitrary collection of objects to the pivot grid. For example, I dont want to go through RIA to connect to the server, I just want to report on a collection of data I have. The following code does not work:
public
class Data
{
public DateTime Date { get; set; }
public string Ticker {get;set;}
public double Value { get; set; }
}
List
<Data> data = new List<Data>();
data.Add(
new Data{
Date =
DateTime.Parse("1/1/2000"),
Ticker =
"IBM",
Value = 1.0
});
this.xamPivotGrid1.DataSource = data;
It wants an instance of IOlapViewModel
Thanks in advance
Hi
To provide data to XamPivotGrid you should create DataSource that XamPivotGrid can read. Such oblects are FlatDataSource and XmlaDataSource. The first type is used when you have IEnumerable and want to show this data in the grid. The second type is used when you have analysis server as MS SQL Analysis server 2008. In your case you should FlatDataSource. Below is the code you can use to provide your data:
List<Data> data = new List<Data>();
data.Add(new Data
Date = DateTime.Parse("1/1/2000"),
Ticker = "IBM",
FlatDataSource flatDataSource = new FlatDataSource
ItemsSource = data,
Cube = DataSourceBase.GenerateInitialCube("Data"),
Rows = DataSourceBase.GenerateInitialItems("[Date]"),
Columns = DataSourceBase.GenerateInitialItems("[Ticker]"),
Measures = DataSourceBase.GenerateInitialItems("Value")
};
pivotGrid.DataSource = flatDataSource;
The cube is your class that contains properties with data – here is “Data”. For rows and columns you should provide properties whose data will be shown in rows or in column and for measure you provide property with data for cells. Finally you have to assign XamPivotGrid’s DataSource samples. In addition you can use HierarchyDescriptor<Data> to customize the look of the data in rows, columns and cell. You can see more complex sample about HierarchyDescriptor here http://labs.infragistics.com/silverlightdv/2010.2/#/Samples/PivotGrid/Basic/DataSourceFlatDataCB
Regards
Todor
Hi, thanks for the post. Am a beginner with Netadvantage infragistics. I have been trying to get myself acquainted with the xampivotgrid control. I have used the above code in a project and I have put code for assigning the datasource to the pivotgrid in a click event of a button. however, when i run the project nothin happens. is there something am missing?
basically what am trying to do is have a simple datasource from which i can display the data in the contol, say even a mysql database. i have gone through the documentation on the help site but it doesnot give much detail. any help will be greatly appreciated. thanks in advance
Hello,
When I use the RIA I create the instance of DomainDataSource into resources of the layout root
<Grid.Resources>
…
<riaControls:DomainDataSource x:Key="ddsProducts"
AutoLoad="True"
LoadedData="productDomainDataSource_LoadedData"
Name="productDomainDataSource" QueryName="GetProducts">
<riaControls:DomainDataSource.DomainContext>
<web:ProductsDomainContext/>
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<FlatData:FlatDataConnectionSettings x:Key="flatDataSettings"
ItemsSource="{Binding Source={StaticResource ddsProducts}, Path=Data}"/>
<FlatData:FlatDataSource x:Key="flatDataSource"
Cube="ProductData"
ConnectionSettings="{StaticResource flatDataSettings}">
Then I set the bindings as follow
<PivotGrid:XamPivotGrid x:Name="pivotGrid"
DataSource="{StaticResource flatDataSource}">
</PivotGrid:XamPivotGrid>
<PivotGrid:Expander Header="RIA data" Grid.Column="1" IsExpanded="True">
<PivotGrid:XamPivotDataSelector Grid.Column="1" x:Name="dataSelector"
DataSource="{StaticResource flatDataSource}"/>
</PivotGrid:Expander>
Also you can check the event handler of LoadedData event for errors or exceptions.
Regards.Plamen.
Plamen,
Can you give more details on "DomainDataSource.Data property as ItemsSource of FlatDataSource" I'm trying to bind xamPivotGrid with RIS Services. But not getting any data. So trying to genrate FlatdataSource out of my DomaindataSource.
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:vwTranDetail, CreateList=true}" Height="0" LoadedData="vwTranDetailDomainDataSource_LoadedData" Name="vwTranDetailDomainDataSource" QueryName="GetVwTranDetailsQuery" Width="0">
<my:CSFContext /></riaControls:DomainDataSource.DomainContext>
<ig:XamPivotGrid x:Name="pivotGrid" Grid.Column="0" DataSource="{Binding Source=vwTranDetailDomainDataSource, Path=Data}" />
Thanks for your help
Sandip
Hello Tonny,
Do you use RIA services or you have your own service to process the database? If you are using RIA services then you can set DomainDataSource.Data property as ItemsSource of FlatDataSource. FlatDataSource is sensitive about DispalyAttribute.AutoGenerateField, DispalyAttribute.Name and DispalyFormatAttribute.DataFormatString metadata.
Plamen.
YOu know what, finally the above code worked. Am now trying to to use the xampivotgrid on a database but clueless on how to do that. Will be greatful for any help provided. thanks