Ticket Q470029
Visible to All Users

GridView - PageSize in a Pager Template via Custom Callback

created 12 years ago

I have a pager template that I use on all my grids. My pager template has the ability to change the page size just like the default pager. I would have thought that this functionality would be supported through client side scripts, just like all the other standard methods and properties associated with the pager:

.GotoPage()
.NextPage()
.PrevPage()
.PageCount
.PagerIndex

If setting the PageSize using a client side script is available, I can't find it. Nevertheless, I found a way to set the PageSize by reviewing some of the other responses on your site. The way I'm doing it requires no additional code in the controllers, however, at some point I started getting a warning around the following code:

@Html.DevExpress().GridView(
settings =>
{

settings.CustomCallback = (sender, e) =>
{
int rowCount = Int32.Parse(e.Parameters);
MVCxGridView grd = (MVCxGridView)sender;
grd.SettingsPager.PageSize = rowCount;
grd.DataBind();
};

}).Bind(Model).GetHtml()

The warning is :

Warning: 'DevExpress.Web.Mvc.GridViewSettings.CustomCallback' is obsolete: '"Use the GridViewSettings.CustomActionRouteValues property instead."'

I don't quite understand what I should do to fix this without changing the code in every single controller. Please see the attached project. Any insight you can give me would be greatly appreciated.

Thanks,
Gene

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hello Gene,
There is no yet the client-side API avaliable for the PageSize selector. So, your solution with a custom PageSize selector is correct.
The compilation warning is caused by the fact that we have changed the behavior of the CustomCallback delegate. See the GridViewSettings.CustomActionRouteValue topic for details:
View:

C#
@Html.DevExpress().GridView(settings => { settings.CustomActionRouteValues = new { Controller = "Home", Action = "CustomTemplatesPartial" }; settings.BeforeGetCallbackResult = (sender, e) => { MVCxGridView grid = (MVCxGridView)sender; if(ViewData["PageSize"] != null) { int pageSize = Convert.ToInt32(ViewData["PageSize"]); if(grid.SettingsPager.PageSize != pageSize) { grid.SettingsPager.PageSize = pageSize; grid.DataBind(); } } }; }).Bind(Model.States).GetHtml()

Controller:

C#
public ActionResult CustomTemplatesPartial(int pageSize) { StatesModel model = new StatesModel(); if(pageSize > 0) { ViewData["PageSize"] = pageSize; } return PartialView("IndexPartial", model); }

I have modified your project according to the new implementation. Please refer to the attachment.
See Also:
Grid View - Templates

    Comments (3)

      Mike,
      Thanks for your response and the updated project. The only problem with this solution is that it requires me to update every single controller in all my projects. The standard GridView pager does not require this. I would recommend you add this to the client-side API.
      Just FYI: The link you provided to GridViewSettings.CustomActionRouteValue, does not seem to be valid.
      Thanks again,
      Gene

        Mike,
        One last thing. I noticed that if I do not implement CustomActionRouteValues, but just update my ActionResult called by CallbackRouteValues, using the code you supplied, that it works fine:
        public ActionResult IndexPartial(int pageSize)
        {
             if (pageSize > 0)
            {
                ViewData["PageSize"] = pageSize;
            }

        StatesModel model = new StatesModel();
           return PartialView("IndexPartial", model);
        }
        Adding a pageSize parameter and a few lines of code to each of my GridView callbacks would be an easier fix for me. See attached projet. Is there a reason that I should not to it this way?
        Gene

          Hello Gene,
          >>Is there a reason that I should not to it this way?
          I believe you can use this solution if you do not want to implement Custom Binding.
          >>Just FYI: The link you provided to GridViewSettings.CustomActionRouteValue, does not seem to be valid.
          It seems that we have not published the latest documentation yet. The link will become available after the next online documentation update.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.