Show the Total Count of Items in RadDataPager.
Environment
| Product Version | 2022.3.912 |
| Product | RadDataPager for WPF |
Description
How to show the total count of all items in the RadDataPager control in a RadGridView scenario.
Solution
-
Subscribe to the
Loadedevent of theRadDataPagercontrol and retrieve the firstGridpanel using the ChildrenOfType extension method. -
Add a new
ColumnDefinitionwithWidthset toAuto, to theColumnDefinitionsproperty if the retrieved Grid panel. -
Move the last child element of the Grid panel to the newly added ColumnDefinition using the
Grid.SetColumnmethod. -
Create a new element to display the total count of the entries and bind it to the
TotalItemCountproperty of theItemsSourceproperty ofRadGridViewinstance. -
Set the newly added element to the second column via the Grid.SetColumn method and add it to the
Childrencollection of the Grid panel.
Sample implementation
private void RadDataPager_Loaded(object sender, RoutedEventArgs e)
{
RadDataPager radDataPager = (RadDataPager)sender;
//Retrieve the Grid panel
Grid gridPanel = radDataPager.ChildrenOfType<Grid>().FirstOrDefault();
if (gridPanel != null)
{
//Include an additional ColumnDefinition to the ColumnDefinitions of the Grid panel and set its Width to Auto
gridPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(0, GridUnitType. Auto) });
//Change the Grid.Column attached property for the element that holds the current page information
Grid.SetColumn(gridPanel.Children[1], 2);
//A StackPanel that will hold the total entries information (Different panel can be used if needed)
StackPanel totalInfoPanel = new StackPanel()
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center,
};
Grid.SetColumn(totalInfoPanel, 1);
TextBlock text = new TextBlock() { Text = "Total entries:", Margin = new Thickness(0, 0, 3, 0) };
TextBlock totalText = new TextBlock();
//Bind the ItemsSource.TotalItemCount property of the RadGridView instance to the Text property of the created TextBlock
BindingOperations.SetBinding(totalText, TextBlock.TextProperty, new Binding("ItemsSource. TotalItemCount") { ElementName = "gridView" });
totalInfoPanel.Children.Add(text);
totalInfoPanel.Children.Add(totalText);
//Add the created StackPanel to the Grid panel
gridPanel.Children.Add(totalInfoPanel);
}
}RadDataPager displaying the total items count
