New to Telerik UI for WinUI? Download free 30-day trial

DataView

The IDataView interface provides access to the view generated from the data displayed in the RadDataGrid instance.

The Items in the IDataView can differ from the ones in the ItemsSource when a data operation is applied (grouping, sorting, filtering etc.).

Before using the IDataView, make sure to check the IDataView.IsDataReady property or use the DataBindingComplete event or command.

The actual implementation of 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 may be properly accessed.
  • Items: Gets the top-level items within the view. They might be either IDataGroup instances, or business objects if no grouping is applied.

Methods

  • GetAggregateValue(int aggregateIndex, IDataGroup group): Gets the computed aggregate value associated with the provided aggregate index.

    • aggregateIndex: The zero-based index of the AggregateDescriptorBase within the RadDataGrid.AggregateDescriptors collection.
    • group: The IDataGroup instance to get the value for. Pass null to retrieve the computed grand total value.
  • GetAggregateValues(string propertyName, IDataGroup group): Gets the computed aggregate values for all the PropertyAggregateDescriptor instances associated with the provided property name.

    • propertyName: The name of the property to filter aggregates by.
    • group: The IDataGroup instance to get the value for. Pass null to retrieve the computed grand total value.
  • GetGroups(Predicate condition = null): Enumerates all the present IDataGroup instances using depth-first approach. An optional condition may be used to filter the results.

  • GetIsExpanded(IDataGroup group): Determines whether the provided group is considered "expanded" - that is to have its ChildItems available within the UI.

  • GetParentGroup(object item): Gets the IDataGroup instance where the specified item resides. This method will return null, if no grouping is applied or the item does not belong to the ItemsSource of the grid.

  • ExpandGroup(IDataGroup group): Attempts to expand the provided IDataGroup instance.

Example 1: Using 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 provided IDataGroup instance.

Example 2: Using the CollapseGroup method

var currentView = this.dataGrid.GetDataView(); 
 
if (currentView.IsDataReady) 
{ 
    currentView.CollapseGroup(currentView.Items[0] as IDataGroup); 
} 
  • ExpandAll(): Expands all the groups.

Example 3: Using the ExpandAll method

var currentView = this.dataGrid.GetDataView(); 
 
if (currentView.IsDataReady) 
{ 
    currentView.ExpandAll(); 
} 
  • CollapseAll(): Collapses all the groups.

Example 4: Using 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.

Example 5: Using 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.

Example 6: Using the CollapseItem method

var currentView = this.dataGrid.GetDataView(); 
 
if (currentView.IsDataReady) 
{ 
    currentView.CollapseItem(this.dataGrid.SelectedItem); 
} 

Using the DataBindingComplete Command

Examples 7 demonstrate how to create a command that collapses all groups except the first one each time when the RadDataGrid is grouped. Example 8 shows how to add the custom command to the Commands of the RadDataGrid.

Example 7: 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); 
    } 
} 

Example 8: Adding 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> 

See Also

In this article
Not finding the help you need?