CMS Repeater UniPager shows everything on one page

SOS Childrensvillages asked on November 30, 2020 13:31

I have the following code in front:

<cms:CMSRepeater ID="RepItems" runat="server" DataBindByDefault="false">
    <ItemTemplate>
        //code
    </ItemTemplate>
</cms:CMSRepeater>
<div class="paging-bar flex">
    <cms:UniPager ID="Pager" runat="server">
        <PageNumbersTemplate>
            //template code here
        </PageNumbersTemplate>
    </cms:UniPager>
</div>

And in the code behind I call this method in SetupControl()

var data = //call to webservice
if (!DataHelper.DataSourceIsEmpty(data))
{
RepItems.DelayedLoading = true;
RepItems.DataSource = data;
DataBind();
RepItems.ControlContext = ControlContext; //tried with and without
RepItems.EnablePaging = true; //tried with and without
RepItems.PageSize = PagingPageSize; //tried with and without
RepItems.UniPagerControl = Pager; //tried with and without


Pager.PageSize = PagingPageSize;
Pager.DisplayFirstLastAutomatically = true;
Pager.DisplayPreviousNextAutomatically = true;
Pager.HidePagerForSinglePage = true;
Pager.GroupSize = 3;
Pager.PageControl = RepItems.ID;
Pager.UseQueryParameterForFirstPage = true;
Pager.PagerMode = CMS.DocumentEngine.Web.UI.UniPagerMode.Querystring;

//DataBind();
}

But the repeater shows all the items with no paging. Is there something I'm missing? When debugging I get the expected values for PagingPageSize but Repeater.PageCount always gives me a value of 1.

I've followed everything according to the K12 docs https://docs.xperience.io/k12sp/developing-websites/kentico-controls/generic-controls/paging-controls/unipager

Recent Answers


Brenden Kehren answered on December 3, 2020 18:54

A cms:CMSRepeater already has a pager built-in. I suggest using a basic repeater to attach your datasource and pager to. This has worked much better for me in the past.

If you wish to use the repeater you have, go with a minimalist approach on setting properties. Remove the following:

RepItems.ControlContext = ControlContext; 
RepItems.EnablePaging = true; // tells the repeater to use the built-in pager
RepItems.PageSize = PagingPageSize; // setting the built-in pager properties
RepItems.UniPagerControl = Pager; 

Don't set any of the pager properties on the repeater as those will assign/set values for the built-in pager of the repeater.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.