Programatically set default pagesize in grid

10 posts, 0 answers
  1. Anthony
    Anthony avatar
    7 posts
    Member since:
    Nov 2013

    Posted 07 May 2014 Link to this post

    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.
  2. Anthony
    Anthony avatar
    7 posts
    Member since:
    Nov 2013

    Posted 07 May 2014 in reply to Anthony Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 May 2014 in reply to Anthony Link to this post

    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
  5. Anthony
    Anthony avatar
    7 posts
    Member since:
    Nov 2013

    Posted 08 May 2014 in reply to Princy Link to this post

    And it works! Thank you very much!
  6. Anthony
    Anthony avatar
    7 posts
    Member since:
    Nov 2013

    Posted 08 May 2014 in reply to Princy Link to this post

    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?
  7. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 09 May 2014 Link to this post

    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.

     
  8. Anthony
    Anthony avatar
    7 posts
    Member since:
    Nov 2013

    Posted 09 May 2014 in reply to Pavlina Link to this post

    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.
  9. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 13 May 2014 Link to this post

    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.

     
  10. Has
    Has avatar
    5 posts
    Member since:
    Jun 2015

    Posted 07 Sep Link to this post

    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

  11. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 07 Sep Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017