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 eitherIDataGroup
instances, or business objects if no grouping is applied.
Methods
-
GetAggregateValue
(intaggregateIndex
,IDataGroup
group)—Gets the computed aggregate value associated with the provided aggregate index.-
aggregateIndex
—The zero-based index of theAggregateDescriptorBase
within theRadDataGrid.AggregateDescriptors
collection. -
group
—TheIDataGroup
instance to get the value for. Passnull
to retrieve the computed grand total value.
-
-
GetAggregateValues
(stringpropertyName
,IDataGroup
group)—Gets the computed aggregate values for all thePropertyAggregateDescriptor
instances associated with the provided property name.-
propertyName
—The name of the property to filter aggregates by. -
group
—TheIDataGroup
instance to get the value for. Passnull
to retrieve the computed grand total value.
-
GetGroups
(Predicate<IDataGroup> condition = null
)—Enumerates all the presentIDataGroup
instances by using depth-first approach. You can use an optional condition to filter the results.GetIsExpanded
(IDataGroup
group)—Determines whether the provided group is considered "expanded", that is, to have itsChildItems
available within the UI.GetParentGroup
(object
item)—Gets theIDataGroup
instance where the specified item resides. This method will returnnull
, if no grouping is applied or the item does not belong to theItemsSource
of the grid.-
ExpandGroup
(IDataGroup
group)—Attempts to expand the providedIDataGroup
instance.Use the ExpandGroup Method
var currentView = this.dataGrid.GetDataView(); if (currentView.IsDataReady) { currentView.ExpandGroup(currentView.Items[0] as IDataGroup); }
-
CollapseGroup
(IDataGroup
group)—Attempts to collapse the providedIDataGroup
instance.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
(object
item)—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
(object
item)—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>