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

Programatically set default pagesize in grid

9 Answers 302 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 07 May 2014, 01:38 PM
How can I programatically set the default pagesize in a grid depending on the number of items in the grid? I want it to be proportionate to the number of total items. Basically limiting the paging to a certain number of pages, rather than the number of items per page. I’ve seen some examples to do this when using the combobox for the PagerStyle, but we’re using the “NextPrevNumericAndAdvanced” and I want it to be the default value. Thanks.

9 Answers, 1 is accepted

Sort by
0
Anthony
Top achievements
Rank 1
answered on 07 May 2014, 02:43 PM
I am trying to use the RadGrid.PageSize method to set the page size to a number that is set to the total number of records returned, but it doesn't appear to be working in any place I put it. The grid still defaults to 10 records per page, even though I've also removed the pagesize property from the front end.
0
Princy
Top achievements
Rank 1
answered on 08 May 2014, 05:36 AM
Hi Anthony,

You can get the total count of rows in the PreRender event and there you can set the PageSize and Rebind the Grid.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
 int rowCount;
 RadGrid1.MasterTableView.AllowPaging = false;
 RadGrid1.Rebind();
 rowCount = RadGrid1.MasterTableView.Items.Count;//get row count
 RadGrid1.PageSize = rowCount; //set page size
 RadGrid1.MasterTableView.AllowPaging = true;  
 RadGrid1.Rebind();
}

Thanks,
Princy
0
Anthony
Top achievements
Rank 1
answered on 08 May 2014, 12:08 PM
And it works! Thank you very much!
0
Anthony
Top achievements
Rank 1
answered on 08 May 2014, 12:19 PM
Actually upon further investigation it seems the code is called every time a page is changed. My code is below:

int rowCount;
radGridVessel.MasterTableView.AllowPaging = false;
radGridVessel.Rebind();
rowCount = radGridVessel.MasterTableView.Items.Count;//get row count
radGridVessel.PageSize = (rowCount / 2) + 1; //set for 2 pages
radGridVessel.MasterTableView.AllowPaging = true;
radGridVessel.Rebind();

The code presents an issue because on load, the first page will be correct proportionately, but when the next page button is pressed, the code is executed again, essentially halving the page size each time the button is pressed. How can I keep this to persist across changing pages?
0
Pavlina
Telerik team
answered on 09 May 2014, 02:46 PM
Hello Anthony,

I am not sure what exactly you want to persist across changing pages - the initial PageSize or not?
I have tested the provided code and it works as expected. When the grid is initially loaded the row count is set for 2 pages as it should be. After I change the page by clicking next/prev button or the number the PageSize is persisted. Once I change the PageSize value and start changing the pages again the new PageSize is displayed for the grid. You can also refer to this video which demonstrates how this approach is working on my end:
http://screencast.com/t/jpXf9Zx3Bu

If you expect something different, please elaborate more what is the desired behavior.

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Anthony
Top achievements
Rank 1
answered on 09 May 2014, 03:19 PM
That is the desired behavior I am looking for, but see my screenshot for what is occurring when I change pages using the code I have. Each screenshot represents what the grid looks like after the next page is selected. I have the groups collapsed by default also.
0
Pavlina
Telerik team
answered on 13 May 2014, 02:50 PM
Hello Anthony,

Could you please try to replicate the described behavior in the project I sent you in the previous post and let me know what steps I should follow in order to observe it locally? Another option would be to isolate the problem in a sample runnable project and send it to us via Support ticket. Once we manage to replicate the issue we would be able to advice you further.

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Has
Top achievements
Rank 1
answered on 07 Sep 2016, 01:01 PM

Hi I'm having exactly the same issue.

 

I want to change radgrid default pageSize programmatically.  Basically I want to give different radgrid PageSizes to different users. 
after reloading the page it goes back to original default pageSize. 




I'm using  < PagerStyle Mode="NextPrevNumericAndAdvanced" ...........</PagerStyle>

                    <ClientSettings AllowColumnsReorder="true" ReorderColumnsOnClient="true" >
                        <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" />
                        <DataBinding Location="xxxxxxx.asmx" SelectMethod="xxxxxxx" SelectCountMethod="SessionExpired">
                        </DataBinding>
                       
                        <ClientEvents OnDataBound="RadGrid_DataBound" OnDataBinding="RadGrid_DataBinding" OnRowSelected="Radgrid_onItemSelect" OnRowDeselected="RadGrid_onItemDeSelect" OnRowContextMenu="xxxxxx"></ClientEvents>
                        
                        <Selecting AllowRowSelect="True"></Selecting>
                        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                    </ClientSettings>


I don't want to use RadComboBox dropdown for pageSize. 

Could you please help me on this ?

Cheers
Has

0
Marin Bratanov
Telerik team
answered on 07 Sep 2016, 02:13 PM

Hi Has,

I see your other thread with the same question is already answered: http://www.telerik.com/community/forums/change-radgrid-default-pagesize.

Regards,

Marin Bratanov
Telerik by Progress
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
Anthony
Top achievements
Rank 1
Answers by
Anthony
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Pavlina
Telerik team
Has
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or