Limiting the number of total records used in paging

7 posts, 0 answers
  1. Chris
    Chris avatar
    4 posts
    Member since:
    Sep 2010

    Posted 16 Nov 2010 Link to this post

    Good day.

    I inherited a document lister, and I swapped the list over to be a RadListView. The  paging just worked as it was without switching to RadDataPager, and without setting AllowCustomPaging.

    However, I want to be able to limit the amount of data that will be paged. The list is bound to an IQueryable of documents, and this queries in to a DB which returns dozens (or more) records. However, I only want to be able to page through X number of pages. For instance, the list I am binding to had a count of 100, but I only want to set paging to 5 per page, with a maximum of 15 (total of 3 pages).

    I tried applying AllowCustomPaging=true, and using the VirtualItemCount=15, and it does cap it at a max of 15 records, but now my paging links don't work (presumably because I am not handling all of the right events and doing all I have to do to implement custom paging).

    Is there something simple I can do to the following code to simply limit the total number of pages/records, or am I going to have to fully implement custom paging? Otherwise, if I switch to using RadDataPager, can this limit the total number of records? If so, how?

    Thanks,

    Chris

    Here is the aspx code:

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div class="WidgetDocumentBullet WidgetLink">
                <ul id="DocumentsList" runat="server">
                    <telerik:RadListView ID="RadListView1" runat="server"
                        ItemPlaceholderID="LatestDocsContainer" PageSize="5"  AllowPaging="true" EnableTheming="true"  OnNeedDataSource="RadListView1_NeedDataSource" >
                        <LayoutTemplate>
                            <asp:Panel ID="PanelLatestDocs" Width="100%" runat="server">
                                <asp:PlaceHolder ID="LatestDocsContainer" runat="server"/>
                                <div style="text-align:center;padding-top:10px">
                                    <asp:LinkButton  runat="server" ID="btnPrev" CommandName="Page" CommandArgument="Prev"
                                        Text="Prev" Enabled="<%#Container.CurrentPageIndex > 0 %>" />
                                    <span style="vertical-aligntoppositionrelative;">
                                        <%#Container.CurrentPageIndex + 1 %>
                                        of
                                        <%#Container.PageCount %></span>
                                    <asp:LinkButton runat="server" ID="btnNext" CommandName="Page" CommandArgument="Next"
                                        Text="Next" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" />
                                </div>
                            </asp:Panel>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <li>
                                <a target="_blank" runat="server" id="link" href='<%# ((Web.WidgetFramework.Utilities.DocumentDisplay) Container.DataItem).Link %>'>
                                    <%# ((Web.WidgetFramework.Utilities.DocumentDisplay)Container.DataItem).Name%>
                                </a> <nobr><small style="color:Black;"><%# ((Web.WidgetFramework.Utilities.DocumentDisplay)Container.DataItem).Date.ToString("MMMM d, yyyy")%></small></nobr>
                            </li>
                            <br />
                        </ItemTemplate>
                    </telerik:RadListView>
                </ul>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 19 Nov 2010 Link to this post

    Hello Chris,

    There is no straightforward way to do this at the control level. You can set AllowCustomPaging="True" and specify the VirtualItemCount property. But this scenario also implies that you will be handling paging manually (hence the notion of "custom paging"). So, you will have to manually page your data source and provide RadTreeList only the current page of the data.

    Isn't using IQueryable's Skip() and Take() methods suitable for you? Using them you can limit the retrieved records to a specified subset of all data records and RadListView will only know about this subset. Thus, no further configuration for RadListView will be required.

    Veli
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chris
    Chris avatar
    4 posts
    Member since:
    Sep 2010

    Posted 19 Nov 2010 Link to this post

    Yes, right you are! It was just as straight forward to use Skip/Take and do my own paging.

    However, my final hurdle seems to be that now the PageCount is off. If, for instance, I have a total of 7 records to display, and I have PageSize=5 and VirtualItemCount=15, my paging links still say there is a total of 3 pages instead of 2.

    Am I doing something silly here, or is there something else I'm supposed to set (or not set) on the control?

    The ascx is below.

    Thanks,

    Chris

                    <telerik:RadListView ID="RadListView1" runat="server" ItemPlaceholderID="LatestDocsContainer" PageSize="5" 
                        AllowPaging="true" AllowCustomPaging="true" VirtualItemCount="15" EnableTheming="true"  OnNeedDataSource="RadListView1_NeedDataSource"
                         OnPageIndexChanged="RadListView1_PageIndexChanged">
                        <LayoutTemplate>
                            <asp:Panel ID="PanelLatestDocs" Width="100%" runat="server">
                                <asp:PlaceHolder ID="LatestDocsContainer" runat="server"/>
                                <div style="text-align:center;padding-top:10px">
                                    <asp:LinkButton  runat="server" ID="btnPrev" CommandName="Page" CommandArgument="Prev"
                                        Text="Prev" Enabled="<%#Container.CurrentPageIndex > 0 %>" />
                                    <span style="vertical-aligntoppositionrelative;">
                                        <%#Container.CurrentPageIndex + 1 %>
                                        of
                                        <%#Container.PageCount %></span>
                                    <asp:LinkButton runat="server" ID="btnNext" CommandName="Page" CommandArgument="Next"
                                        Text="Next" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" />
                                </div>
                            </asp:Panel>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <li>
                                <a target="_blank" runat="server" id="link" href='<%# ((Web.WidgetFramework.Utilities.DocumentDisplay) Container.DataItem).Link %>'>
                                    <%# ((Web.WidgetFramework.Utilities.DocumentDisplay)Container.DataItem).Name%>
                                </a> <nobr><small style="color:Black;"><%# ((Web.WidgetFramework.Utilities.DocumentDisplay)Container.DataItem).Date.ToString("MMMM d, yyyy")%></small></nobr>
                            </li>
                            <br />
                        </ItemTemplate>
                    </telerik:RadListView>

  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 22 Nov 2010 Link to this post

    Your VirtualItemCount should properly reflect the total number of items.

    Veli
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  6. Chris
    Chris avatar
    4 posts
    Member since:
    Sep 2010

    Posted 22 Nov 2010 Link to this post

    But what if I don't know how many items there are? The returned list of items will be different for every user depending on what permissions they have to see certain items. As well, any individuals list will change as some items are added to or removed from the DB. I have absolutely no way of knowing how many total items there are until I query the DB, but I'm using skip/take to only retrieve a small amount, not the total.

    This said, are you suggesting that I need to update VirtualItemCount every time I update the list? This isn't a very nice option as that means I need to get a total count in the DB as well as just get the records I want every time I refresh this list.

    Is there no way for me to set it up such that this VirtualItemCount is my MAXIMUM number of items, but if I have fewer items I only present pages enough to contain them?
    Thanks,

    Chris
  7. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 23 Nov 2010 Link to this post

    Hello Chris,

    If you don't know how many items you can page through, there is no way RadListView can know either. The control needs a number indicating how many items there exist for it to page. This is required, so that RadListView can setup its page count. You can set the VirtualItemCount to the number of returned items in the NeedDataSource event of the control. In this case, RadListView will assume only that many items exist and will setup paging accordingly. If your page size is smaller than the total virtual item count, you will get your data in a number of pages. Otherwise, your items will show in a single page.

    If this is not what you need, can you, please, clarify?

    Greetings,
    Veli
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  8. Chris
    Chris avatar
    4 posts
    Member since:
    Sep 2010

    Posted 13 Dec 2010 Link to this post

    Thanks for the reply.

    I ended up putting in caching so that I am caching the complete list (so that I know how big the entire list is and so how many total pages I have), and then just using Skip/Take on that list to return the required records for the given page.

    This helped me avoid constantly having to query for the whole set every time I changed page.

    Thanks for the help!

    Chris
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017