Document page index handling in QuickGrid#37020
Conversation
There was a problem hiding this comment.
Pull request overview
Adds documentation and a cut-and-paste sample showing how to preserve and restore a QuickGrid page index when navigating to a details page and back.
Changes:
- Document
PaginationState.CurrentPageIndexandPaginationState.SetCurrentPageIndexAsyncfor saving/restoring paging state. - Add
Details.razorandCharacters.razorexample snippets using query string parameters to round-trip the page index.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Luke Latham <1622880+guardrex@users.noreply.github.com>
Are you maybe able to find an issue with this ask? We have a quite big issue about scroll position dotnet/aspnetcore#26943 but the ask there is to set the position, not get it. I didn't treat it as a required/ask for feature when designing for scroll-to-index. In fact, such an API would be very costly. I would like more about where did this request originate from. I have an impression that the sample is more about pagination than scroll position. If it's pagination, I believe dotnet/aspnetcore#65451 is adding pagination functionality that you need. We should edit the doc to use the approach from the PR. cc @dariatiurina, I believe you could help Luke here. |
That's correct for this scenario, but let's discuss terminology in the docs first ... For discussion just so that we're using the same terminology, the docs make careful, specific use of "SSR." In the docs, "SSR" merely means "server-side rendering" (as opposed to "CSR"/"client-side rendering," while "static SSR" means "static server-side rendering" and "interactive SSR" means "interactive server-side rendering." It's useful in the docs to make those distinctions and not use "SSR" to mean "static server rendering." Here are how the docs break down and use these terms for rendering concepts ...
It looks like your PR, @dariatiurina, is delivering QuickGrid features for static SSR in >=11.0 that normally work in <11.0 only for interactive SSR. This docs PR isn't assuming SSR at all ... either type. The approach on this docs PR should work with CSR as well. I don't think that I have an issue for the original ask. The ask was from several years ago on I think an unrelated issue discussion with a dev about a custom grid that was being used in the EF Core-Blazor sample app, which we don't even maintain any longer. There was some overlap between that sample's manual grid approach and QuickGrid, but we never got around to putting a QuickGrid into that app. That app had a main page-detail page setup for EF Core examples. The user selects a record in the main page of paged results that opened a separate detail page (separate component). When the user was returned to the main page, the app did not return them to the correct page of filtered results. The idea for this docs PR is just that it would be nice to show how to open a detail record in a new page (a different component) and then have a way to get back to the original QuickGrid page of paged (possibly filtered, too) results at the spot the user left. I think it can be done using There's no rush on this. Wait until you get a few minutes to look, and we'll see if this is worth showing (I think it is) and if I created a decent 🦖 RexHacks!™ 🦖🙈😆 example using |
dariatiurina
left a comment
There was a problem hiding this comment.
Thank you for this work! I think that it would be better to have everything revolve around URL-based navigation without setting page manually in the state.
|
And also note: this is an opt-out feature, so maybe there should be some note about feature flag? |
|
Thanks! Two things come to mind ...
I'll work on this PR today and tomorrow and ping you back. I think we're headed in a great direction with it! 👍 |
|
@dariatiurina ... Neither of your suggestions seems to work here. Adding For reference in case you want to drop them into a test app, here are the 🦖 RexHacks!™ 🦖🙈😆 components that I've had luck with ...
@page "/characters"
@rendermode InteractiveServer
@using Microsoft.AspNetCore.Components.QuickGrid
<QuickGrid Items="character" Pagination="pagination">
<PropertyColumn Property="@(c => c.Id)" />
<PropertyColumn Property="@(c => c.Name)" />
<TemplateColumn Context="c">
<a href="@($"/details?id={c.Id}&page={pagination.CurrentPageIndex}")">
Details
</a>
</TemplateColumn>
</QuickGrid>
<Paginator State="pagination" />
@code {
PaginationState pagination = new PaginationState { ItemsPerPage = 3 };
private record Character(int Id, string Name);
private IQueryable<Character> character = new[]
{
new Character(0, "Ellen Ripley"),
new Character(1, "Darth Vader"),
new Character(2, "Rick Deckard"),
new Character(3, "Sarah Connor"),
new Character(4, "Malcolm Reynolds"),
new Character(5, "Kara Thrace"),
new Character(6, "James Kirk"),
new Character(7, "Flash Gordon"),
new Character(8, "Max Rockatansky"),
new Character(9, "Katniss Everdeen"),
new Character(10, "Ellie Sattler"),
new Character(11, "Leela")
}.AsQueryable();
[SupplyParameterFromQuery]
private int Page { get; set; }
protected override async Task OnInitializedAsync()
{
await pagination.SetCurrentPageIndexAsync(Page);
}
}
@page "/details"
<ul>
<li>Character ID for this detail record: @Id</li>
<li>QuickGrid page index: @Page</li>
</ul>
<div>
<a href="@($"/characters?page={Page}")">Back to List</a>
</div>
@code {
[SupplyParameterFromQuery]
private int Id { get; set; }
[SupplyParameterFromQuery]
private int Page { get; set; }
}Can you give me your versions of the pair of components that you would recommend so that I can see what you're suggesting in action here? |
|
@guardrex Hi! I don't understand what exactly isn't working for you, because these two components work perfectly fine for me 😥. But I tested them on main in aspnetcore repo in BlazorUnitedApp, so maybe we have different builds and setups?
@page "/characters"
@using Microsoft.AspNetCore.Components.QuickGrid
<QuickGrid Items="character" Pagination="pagination">
<PropertyColumn Property="@(c => c.Id)" />
<PropertyColumn Property="@(c => c.Name)" />
<TemplateColumn Context="c">
<a href="@($"/details?id={c.Id}&page={pagination.CurrentPageIndex+1}")">
Details
</a>
</TemplateColumn>
</QuickGrid>
<Paginator State="pagination" />
@code {
PaginationState pagination = new PaginationState { ItemsPerPage = 3 };
private record Character(int Id, string Name);
private IQueryable<Character> character = new[]
{
new Character(0, "Ellen Ripley"),
new Character(1, "Darth Vader"),
new Character(2, "Rick Deckard"),
new Character(3, "Sarah Connor"),
new Character(4, "Malcolm Reynolds"),
new Character(5, "Kara Thrace"),
new Character(6, "James Kirk"),
new Character(7, "Flash Gordon"),
new Character(8, "Max Rockatansky"),
new Character(9, "Katniss Everdeen"),
new Character(10, "Ellie Sattler"),
new Character(11, "Leela")
}.AsQueryable();
[SupplyParameterFromQuery]
private int Page { get; set; }
}
@page "/details"
<ul>
<li>Character ID for this detail record: @Id</li>
<li>QuickGrid page index: @Page</li>
</ul>
<div>
<a href="@($"/characters?page={Page}")">Back to List</a>
</div>
@code {
[SupplyParameterFromQuery]
private int Id { get; set; }
[SupplyParameterFromQuery]
private int Page { get; set; }
} |
|
Here's what happens when ... protected override async Task OnInitializedAsync()
{
await pagination.SetCurrentPageIndexAsync(Page);
}... isn't present ... movie1.mp4It always loads the Here's what happens when ... pagination.CurrentPageIndex + 1... movie2.mp4It always loads the The only way the Mmmmm ... we can't publish content on this until we agree what works and why each of us can't get the other's approach to work on our respective systems/SDKs. Should we wait until @ilonatommy returns next week to break the tie?! LOL 😆 My setup is ...
|
|
One clarification tho ...
What does "this" refer to? ... and can you give me the code snippet to opt-out of it? |
|
@guardrex Okay, I can see the problem 😊. When you click on the next page in your example, URL doesn't change. Here how it's supposed to look like. I tested it with my components. quickgrid.mp4This is a part of a new URL-based navigation. It's enables by default and you can disable it like this:
|
|
Ah! I see! 😮 ... and WRT "new," you mean new in 11.0? Two things ...
I'll update this PR this afternoon and ping you back. Thanks for solving the mystery here! 🕵️♀️😆 |
|
Yep, it's for 11. Here is PR: dotnet/aspnetcore#65451 and here is issue: dotnet/aspnetcore#51249 You're welcome (^____^) |
|
Closing in favor of #37154. |
Fixes #37019
Ilona ... A few years ago, a dev asked how to make the manually-built grid of an old Blazor Server EF Core sample return the user to the grid at the scroll position† where they left. [IIRC, QuickGrid had just come out at the time. The sample that we were discussing didn't use it. We don't even have that sample anymore.]
What I'd like to do in this area is cover page index management for QuickGrid. At the time, I was too busy to flesh out a page index example, but I reached it for work today. As usual, I want to provide a fully working, cut-'n-paste example. How does this look to you?
†BTW ... AFAIK, scroll position isn't something that can be tracked/set with a QuickGrid. I know that such a grid can be built that would do something like that, but I don't think that the built-in QuickGrid component has such a feature baked into it. If I'm wrong about that ... if there would be some way to preserve scroll position for coming back from a details page, please let me know. 👂
Internal previews