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

Custom Paging - How to set PageCount property ???

9 Answers 1173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ian Coetzer
Top achievements
Rank 2
Ian Coetzer asked on 30 Jun 2008, 02:25 PM
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



9 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 01 Jul 2008, 12:27 PM
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
0
Ian Coetzer
Top achievements
Rank 2
answered on 01 Jul 2008, 02:12 PM
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.
0
Vlad
Telerik team
answered on 01 Jul 2008, 02:45 PM
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
0
Ian Coetzer
Top achievements
Rank 2
answered on 01 Jul 2008, 03:57 PM
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
0
Vlad
Telerik team
answered on 02 Jul 2008, 06:57 AM
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
0
Ian Coetzer
Top achievements
Rank 2
answered on 02 Jul 2008, 10:23 AM
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 

0
Rosen
Telerik team
answered on 07 Jul 2008, 11:37 AM
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
0
ss
Top achievements
Rank 1
answered on 21 Apr 2016, 02:37 AM

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!

0
Viktor Tachev
Telerik team
answered on 26 Apr 2016, 05:22 AM
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.
Tags
Grid
Asked by
Ian Coetzer
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Ian Coetzer
Top achievements
Rank 2
Rosen
Telerik team
ss
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or