grid.mvc

How to do dynamic paging in Grid.MVC


I have using grid.mvc control in my project. I want to use dynamic paging in grid.mvc control. I have combobox having entries 10,25,50. when I change comboBox value. Grid should display data accordingly. ( E.g. when I select 25, grid will show 25 rows). by deafult grid is showing 10 rows at a time. Also it should adjust while filtering records. I tried but didn't found any suitable solution.

Please find screen shot for your references....


Solution

  • This in theory should be pretty easy though I haven't done it myself.

    You can link that dropdown (in the view) to an action result (in the controller) that changes a value you pass to the ViewBag (in controller ViewBag.WhateverName = dropdown's value).

    Then re-render the same view and in the place when you end your grid, end it with

    }).WithPaging(ViewBag.WhateverName)
    

    Basically .WithPaging(10) would give you pages with 10 rows, WithPaging(20) 20 rows per page, etc. So by changing that value with the dropdown and registering that action in the controller to reassign the value, you should be able to achieve this functionality.

    I will keep editing and maybe add controller code later if I have time, just wanted to get something up to help you out. Good luck!