Displaying total number of records on datapager

8 posts, 0 answers
  1. Waseem
    Waseem avatar
    6 posts
    Member since:
    Nov 2011

    Posted 30 Nov 2011 Link to this post

    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! 
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 30 Nov 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Waseem
    Waseem avatar
    6 posts
    Member since:
    Nov 2011

    Posted 02 Dec 2011 Link to this post

    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
  5. Zealous
    Zealous avatar
    2 posts
    Member since:
    Feb 2012
  6. Rakesh
    Rakesh avatar
    19 posts
    Member since:
    Feb 2012

    Posted 29 Aug 2012 Link to this post

    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.
  7. Waseem
    Waseem avatar
    6 posts
    Member since:
    Nov 2011

    Posted 30 Aug 2012 Link to this post

    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!
  8. Rakesh
    Rakesh avatar
    19 posts
    Member since:
    Feb 2012

    Posted 30 Aug 2012 Link to this post

    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
  9. Ubuntu
    Ubuntu avatar
    89 posts
    Member since:
    Jul 2012

    Posted 16 Apr 2013 Link to this post

    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


Back to Top
DevCraft banner