DataView
The IDataView interface provides access to the view generated from the data displayed in the DataGrid instance.
The items in the IDataView can differ from the ones in the ItemsSource when a data operation, such as grouping, sorting, or filtering, is applied.
Before using the IDataView, check the IDataView.IsDataReady property or use the DataBindingComplete event or command.
The actual implementation of the IDataView is stateless and each RadDataGrid.GetDataView method call will return a new object instance.
Properties
-
IsDataReady—Determines whether all the internal data operations are completed and the view can be properly accessed. -
Items—Gets the top-level items within the view. The items can be eitherIDataGroupinstances, or business objects if no grouping is applied.
Methods
-
GetAggregateValue(intaggregateIndex,IDataGroupgroup)—Gets the computed aggregate value associated with the provided aggregate index.-
aggregateIndex—The zero-based index of theAggregateDescriptorBasewithin theRadDataGrid.AggregateDescriptorscollection. -
group—TheIDataGroupinstance to get the value for. Passnullto retrieve the computed grand total value.
-
-
GetAggregateValues(stringpropertyName,IDataGroupgroup)—Gets the computed aggregate values for all thePropertyAggregateDescriptorinstances associated with the provided property name.-
propertyName—The name of the property to filter aggregates by. -
group—TheIDataGroupinstance to get the value for. Passnullto retrieve the computed grand total value.
-
GetGroups(Predicate<IDataGroup> condition = null)—Enumerates all the presentIDataGroupinstances by using depth-first approach. You can use an optional condition to filter the results.GetIsExpanded(IDataGroupgroup)—Determines whether the provided group is considered "expanded", that is, to have itsChildItemsavailable within the UI.GetParentGroup(objectitem)—Gets theIDataGroupinstance where the specified item resides. This method will returnnull, if no grouping is applied or the item does not belong to theItemsSourceof the grid.-
ExpandGroup(IDataGroupgroup)—Attempts to expand the providedIDataGroupinstance.Use the ExpandGroup Method
var currentView = this.dataGrid.GetDataView(); if (currentView.IsDataReady) { currentView.ExpandGroup(currentView.Items[0] as IDataGroup); } -
CollapseGroup(IDataGroupgroup)—Attempts to collapse the providedIDataGroupinstance.Use the CollapseGroup Method
var currentView = this.dataGrid.GetDataView(); if (currentView.IsDataReady) { currentView.CollapseGroup(currentView.Items[0] as IDataGroup); } -
ExpandAll()—Expands all the groups.Use the ExpandAll Method
var currentView = this.dataGrid.GetDataView(); if (currentView.IsDataReady) { currentView.ExpandAll(); } -
CollapseAll()—Collapses all the groups.Use the CollapseAll Method
var currentView = this.dataGrid.GetDataView(); if (currentView.IsDataReady) { currentView.CollapseAll(); } -
ExpandItem(objectitem)—Expands the chain of groups where the specified item resides.Use the ExpandItem Method
var currentView = this.dataGrid.GetDataView(); if (currentView.IsDataReady) { currentView.ExpandItem(this.dataGrid.SelectedItem); } -
CollapseItem(objectitem)—Collapses the immediate groups that contain the specified item.Use the CollapseItem Method
var currentView = this.dataGrid.GetDataView(); if (currentView.IsDataReady) { currentView.CollapseItem(this.dataGrid.SelectedItem); }Using the DataBindingComplete Command
The following examples respectively demonstrate how to create a command that collapses all groups except the first one each time when the DataGrid is grouped, and to add the custom command to the Commands of the DataGrid.
Custom DataBindingComplete Command
public class DataBindingComplete : DataGridCommand
{
public override bool CanExecute(object parameter)
{
if ((parameter as DataBindingCompleteEventArgs).ChangeFlags.HasFlag(DataChangeFlags.Group))
{
return true;
}
else
{
return false;
}
}
public override void Execute(object parameter)
{
this.Owner.GetDataView().CollapseAll();
if (this.Owner.GroupDescriptors.Count > 0)
{
this.Owner.GetDataView().ExpandGroup((this.Owner.GetDataView().Items[0] as IDataGroup));
}
base.Execute(parameter);
}
}
Add the Custom Command to the Commands Collection
<Grid xmlns:telerikGrid="using:Telerik.UI.Xaml.Controls.Grid">
<telerikGrid:RadDataGrid >
<telerikGrid:RadDataGrid.Commands>
<local:DataBindingComplete Id="DataBindingComplete" />
</telerikGrid:RadDataGrid.Commands>
</telerikGrid:RadDataGrid>
</Grid>