This is a migrated thread and some comments may be shown as answers.

Displaying total number of records on datapager

7 Answers 390 Views
DataPager
This is a migrated thread and some comments may be shown as answers.
Waseem
Top achievements
Rank 1
Waseem asked on 30 Nov 2011, 08:33 AM
Hi,
I have RadDataPager that is bound with GridResult and pagesize is also set (i-e 8).
Now, i want to display total number of records (e.g 100 records) found (read only) on data pager.
is there any datapager property through wich i can achieve my goal.

it can be done by placing and binding a textblock on my view but my requirements are to display it on pager.
Thanks! 

7 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 30 Nov 2011, 08:49 AM
Hi,

 You can check IPagedCollectionView for more info.

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Waseem
Top achievements
Rank 1
answered on 02 Dec 2011, 12:18 PM
Thanks Vlad,

I knew of ItemCount property that i can use to get total number of records. Problem i had was to display total number of records on pager.
I have edited the pager template (Expression Blend) and its working for me now.

Thanks for you support.
Regards,
Waseem
0
Zealous
Top achievements
Rank 1
answered on 25 Apr 2012, 11:51 AM
0
Rakesh
Top achievements
Rank 1
answered on 30 Aug 2012, 12:40 AM
I have similar requirement to show total no of records in DataPager. So I tried editing the template and inserted a textblock. I could able to access the textblock in xaml code behind  and assign value in IndexChanged & loaded event.

When page is intially loaded. I don't get total no of records, but if i try to change the index, I get what I wanted.

How can I get total no of records in a RadGrid(i.e totalItemCount) in intial page load.
0
Waseem
Top achievements
Rank 1
answered on 30 Aug 2012, 12:13 PM
Hi Rakesh,
You need to raise GridDataBound event and from there you can get total number of records. You are able to get the total number of records at IndexChnaged because data is already bound to grid while at page_Load event, data is not bound yet.
Kind Regards!
0
Rakesh
Top achievements
Rank 1
answered on 30 Aug 2012, 05:02 PM
Hi Waseem,
Thanks for your help. I could able to get the total count in DataLoaded event of RadGridView. I addition to it, I don't want to write code  in code-behind whereever the datapager is presented. So I have written a behavior where I can use it on any DataPager which displays total count on it in a formated way.

public class DataPagerTotalCountBehavior : Behavior<RadDataPager>
{
    private RadDataPager DataPager
    {
        get
        {
            return AssociatedObject as RadDataPager;
        }
    }
    // Using a DependencyProperty as the backing store for SelectedItemsProperty.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty AssociatedGridProperty =
        DependencyProperty.Register("AssociatedGrid", typeof(RadGridView), typeof(DataPagerTotalCountBehavior), new PropertyMetadata(OnAssociatedGridAssigned));
    private static void OnAssociatedGridAssigned(DependencyObject target, DependencyPropertyChangedEventArgs args)
    {
        var behavior = target as DataPagerTotalCountBehavior;
        if (behavior != null)
        {
          behavior.DataPager_PageIndexChanged(behavior.DataPager,null);
        }
    }
    public RadGridView AssociatedGrid
    {
        get { return (RadGridView)GetValue(AssociatedGridProperty); }
        set { SetValue(AssociatedGridProperty,value); }
    }
    protected override void OnAttached()
    {
        base.OnAttached();
        if (DataPager != null)
        {
            DataPager.PageIndexChanged += new EventHandler<PageIndexChangedEventArgs>(DataPager_PageIndexChanged);
        }
    }
    void DataPager_PageIndexChanged(object sender, PageIndexChangedEventArgs e)
    {
        if (sender != null)
        {
            var page = sender as RadDataPager;
            int result1 = (page.PageIndex * page.PageSize) + 1;
            int result2 = (page.PageSize * (page.PageIndex + 1));
            var recordText = String.Format("Records {0} - {1} of {2} ", result1, result2, page.ItemCount);
            var txtPagerRecordsDisplay =
                page.ChildrenOfType<TextBlock>().Where(i => i.Name == "txtPagerRecordsDisplay").SingleOrDefault() as TextBlock;
            if (txtPagerRecordsDisplay != null) txtPagerRecordsDisplay.Text = recordText.ToString();
        }
    }
     
    protected override void OnDetaching()
    {
        base.OnDetaching();
        DataPager.PageIndexChanged -= DataPager_PageIndexChanged;
    }
}


I need to get => Records (StartCount - EndCount) of TotalItemCount
on RadDataPager.

I could able to do it by placing TextBlock in Template and this behavior on Pager. That's it. Let me know if you have any better solution to achieve this behavior.

Thanks
Rakesh
0
Ubuntu
Top achievements
Rank 1
answered on 16 Apr 2013, 03:28 PM
Hello Rakesh,

    I always found behavior is a great idea, I tried to use the behavior as follows, but the datapager is as is nothing changed.
<telerik:RadDataPager x:Name="radDataPager" Grid.Row="2"
DisplayMode="All" IsTotalItemCountFixed="True"
Source="{Binding Items, ElementName=TaxpayerGrid}" PageSize="20" >
<i:Interaction.Behaviors>
<Behavior:DataPagerTotalCountBehavior AssociatedGrid="{Binding EmpGrid}" />
</i:Interaction.Behaviors>
</telerik:RadDataPager>

where EmpGrid is the name of my grid.
Can you help me with this ...

Best regards


Tags
DataPager
Asked by
Waseem
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Waseem
Top achievements
Rank 1
Zealous
Top achievements
Rank 1
Rakesh
Top achievements
Rank 1
Ubuntu
Top achievements
Rank 1
Share this question
or