aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Single QuickGrid Does Not Support Multiple Paginators

Open jvs7315 opened this issue 1 year ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

In the latest QuickGrid documentation, it's stated that a single <QuickGrid> instance supports multiple paginators (emphasis added):

To provide a UI for pagination, add a Paginator component above, below, or both above and below the QuickGrid component.

However, when two <Paginator> component instances are assigned to the same PaginationState instance, changing the page number via one <Paginator> will not cause the UI of the other <Paginator> to rerender. This causes the other <Paginator> to display an incorrect page number, and it allows that <Paginator>'s page change buttons to navigate beyond the valid range of page numbers.

Expected Behavior

Two or more <Paginator> components linked to the same PaginationState instance should all rerender when one <Paginator> changes the current page number.

Steps To Reproduce

Repro code, based on Microsoft's QuickGrid sample code:

<Paginator State="@pagination" />

<QuickGrid Items="@people" Pagination="@pagination">
    <PropertyColumn Property="@(p => p.PersonId)" Sortable="true" />
    <PropertyColumn Property="@(p => p.Name)" Sortable="true" />
    <PropertyColumn Property="@(p => p.BirthDate)" Format="yyyy-MM-dd" Sortable="true" />
</QuickGrid>

<Paginator State="@pagination" />

@code {
    PaginationState pagination = new PaginationState() { ItemsPerPage = 1 };

    record Person(int PersonId, string Name, DateOnly BirthDate);

    IQueryable<Person> people = new[]
    {
        new Person(10895, "Jean Martin", new DateOnly(1985, 3, 16)),
        new Person(10944, "António Langa", new DateOnly(1991, 12, 1)),
        new Person(11203, "Julie Smith", new DateOnly(1958, 10, 10)),
        new Person(11205, "Nur Sari", new DateOnly(1922, 4, 27)),
        new Person(11898, "Jose Hernandez", new DateOnly(2011, 5, 3)),
        new Person(12130, "Kenji Sato", new DateOnly(2004, 1, 9)),
    }.AsQueryable();
}

Exceptions (if any)

No response

.NET Version

8.0.300

Anything else?

No response

jvs7315 avatar Aug 12 '24 18:08 jvs7315

@jvs7315 thanks for contacting us.

I think this is a case where the docs might need to be corrected. If you have two paginators that share the same state object and one of them changes it, the other one is not going to be notified to trigger a re-render "magically".

@guardrex can you take a look at the docs?

javiercn avatar Aug 13 '24 13:08 javiercn

Thanks @jvs7315 and @javiercn ... I updated the article, and I left myself a note to check back at RC2 to see how this issue plays out for a possible follow-up article update.

guardrex avatar Aug 13 '24 14:08 guardrex

It looks like this could be made to work pretty straightforwardly. The Paginator already subscribes for notifications from PaginationState when the total number of pages changes. It just needs to also subscribe for notifications when the current page changes (in the same way that QuickGrid does). Then any number of Paginator instances will auto-update whenever the PaginationState does.

SteveSandersonMS avatar Oct 16 '24 16:10 SteveSandersonMS

Thanks. Let's start from docs in .NET 9 and we'll reevaluate if we need to take the code change in 10.

mkArtakMSFT avatar Oct 21 '24 16:10 mkArtakMSFT

The docs were updated, so let's use this to track the product change. Moving to .NET 10 planning.

MackinnonBuck avatar Oct 22 '24 22:10 MackinnonBuck