Search code examples
c#razorwebgrid

WebGrid Not staying checked between pages


I have a webgrid that works fine

@{
                    var DB = Database.Open("CHAVI");
                    var grid = new WebGrid(DB.Query("SELECT [FileTrackingTag], FileID FROM (SELECT [FileTrackingTag], FileID, ROW_NUMBER() OVER (PARTITION BY [FileTrackingTag] ORDER BY FileID) rn FROM [dbo].[MasterSequence]) t WHERE rn=1 ORDER BY [FileTrackingTag]"));
                    @grid.GetHtml(
                        tableStyle: "webgrid",
                        columns: grid.Columns(
                            grid.Column(header: "Assign? ", style: "labelcolumn",
                                    format:
                                        @<text><input class="check-box" id="assignChkBx" name="assignChkBx" type="checkbox" value="@item.FileTrackingTag" /></text>),
                            grid.Column("FileTrackingTag", "FileTrackingTag")
                            )
                    )
                 }

However when I check off multiple boxes when I go between different tabs on the WebGrid, only the ones on the current tab get sent over (It is still the same webpage, it is just tabbing through the entries of the webgrid)

Is there a solution to keep them between webgrid tabs?


Solution

  • I am not aware of any built-in way to accomplish what you're talking about. WebGrid paging works by only selecting the data which needs to be displayed at a given time. If you look at your generated HTML for the web page, you'll see that only the "current" items are there.

    Since the data for the other pages is not even in your web page, MVC has no way to know about them. Your best option is really to create an action on your controller and post the current items whenever the page is changed on the grid. You would store those posted items in some temporary storage (a cache, TempData, etc). Then, when the user clicks Save, you'll need to save both the items posted to your Save method and the ones from your temporary storage collection.

    Before going all the way down this route, I'd double-check with the end users and make sure it's what they really want and expect. It takes a decent amount of work to implement correctly, and it might lead to some conclusion when you're updating records that they can't actually see on the screen. Other options would be to disable paging and use a different control, or use some type of wizard flow to make it clear that you're saving results after each "page".