Custom Paging - How to set PageCount property ???

10 posts, 0 answers
  1. Ian Coetzer
    Ian Coetzer avatar
    65 posts
    Member since:
    Sep 2004

    Posted 30 Jun 2008 Link to this post

    Hi

    I have implemented custom paging on one of my Telerik RadGrid's
    I did this making use of a Sql Stored Procedure to return only the number of records - same amount as the PageSize as set on the RadGrid.

    The problem is that my stored procedure only returns say 15 records of the possible 360 records, then when this is bound to the grid which has the PageSize property set to 15 then of course the pager shows 15 records and page 1 of 1. I know that there are 360 records and thus 24 pages of 15 records each, my questions is how to I set the PageCount property to 24 manually so that the user can use the prev/next buttons to get to the next 15 records?

    Thanks



  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 01 Jul 2008 Link to this post

    Hello Ian,

    You can set VirtualItemCount to achieve your goal. More info on this example:
    http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/CustomPaging/DefaultCS.aspx

    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ian Coetzer
    Ian Coetzer avatar
    65 posts
    Member since:
    Sep 2004

    Posted 01 Jul 2008 Link to this post

    Hi

    I tried this but then it still says Page 1 of 1.
    at this stage i don't see any other way of doing this without returning all 360 records and binding them to the grid even though the page size is only 15

    :(

    I would have like to use my special stored procedure to only return 15 records at a time instead of all 360 especially since the database is located 1000km from the web server that hosts the asp.net site.
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 01 Jul 2008 Link to this post

    Hi Ian,

    When the grid is in custom paging mode only PageSize records will be retrieved not all of them.

    Best wishes,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Ian Coetzer
    Ian Coetzer avatar
    65 posts
    Member since:
    Sep 2004

    Posted 01 Jul 2008 Link to this post

    Hi

    I don't think I understand this scenario, because I still have to set the datasource to one of my custom business objects which does the data retrieval and that business object will always return say 360 records for a given parameter., now I have enhanced this business object to also accept the following parameters.

    1. PageSize
    2. Current Page Index

    and based on this new information it calls a clever stored procedure which returns only the PageSize number of records at the correct page index, so if I pass it page index of 3 (it takes pagesize * 3) as the starting row and only returns PageSize records.

    However the RadGrid does not know any of this 'special' retrieval logic in my business object and thinks that the 15 or so records returned (based on page size) is the total records in that dataset, and then says Page 1 of 1.

    This is why I want to somehow tell the RadGrid that 'actually' there are say 7 pages of 15 records each which is 105 records in total.

    Bye
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Jul 2008 Link to this post

    Hi Ian,

    If you set VirtualItemCount the grid will calculate automatically PageCount.

    Best wishes,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Ian Coetzer
    Ian Coetzer avatar
    65 posts
    Member since:
    Sep 2004

    Posted 02 Jul 2008 Link to this post

    Hi,
    Ok but where do I set this VirtualItemCount property? I have tried but it made no difference.

        Private Function GetParts() As System.Data.DataTable  
            Dim DA190Component As New DA190Component()  
            Dim table As System.Data.DataTable = Nothing 
     
            Me.RadGrid1.VirtualItemCount = 360  
          
            'The code below calls my business object and returns only the number of records  
            'as specified by the PageSize property of the rad grid - see parameters.  
     
            table = DA190Component.GetDA190ComponentListView2(ViewState.Item(Constants.PAR_CERTIFICATE_NO), Me.RadGrid1.CurrentPageIndex, Me.RadGrid1.PageSize, ViewState.Item(Constants.PAR_MANAGE_PARTS_FILTER))  
     
            Return table  
    End Function 

    Now this function I call from the following places, so each time it needs data
    like when paging occurs it fires the NeedDataSource event I pressume which in turn will call GetParts() which will ask the business objects for the next set of correct 15 or 10 records - depending on the PageSize (which is fixed at design time)

        Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
            If (Not IsPostBack) Then 
                RadGrid1.DataBind()  
            End If 
        End Sub 

        Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
            RadGrid1.DataSource = GetParts()  
        End Sub 

  9. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 07 Jul 2008 Link to this post

    Hi,

    I attached a simple implementation for the requested scenario. Please give it a try and see if it helps.

    Best regards,
    Rosen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. ss
    ss avatar
    6 posts
    Member since:
    Jan 2015

    Posted 20 Apr Link to this post

    Hi,

    I'm using Telerik.MVC.dll -> Html.Telerik.Grid() and i'm running into same issue.

    HOw do i do custom pagination? How to set the total count? and how do i make the next prev click work for the 2nd page and so on?

    Thanks!

  11. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 26 Apr Link to this post

    Hello,

    You can enable server operations for the grid and use server-side paging. For this you need to configure the DataSource appropriately.


    Alternatively, you can implement custom binding. This way you can use custom logic handle paging/sorting/filtering in order to best fit in your scenario:



    Regards,
    Viktor Tachev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017