Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MudDataGrid to work with MudPagination #8821

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/MudBlazor.UnitTests/Components/DataGridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,20 @@ public async Task DataGridPaginationTest()
// navigate back to the first page programmatically
await comp.InvokeAsync(() => dataGrid.Instance.NavigateTo(Page.First));
dataGrid.Instance.CurrentPage.Should().Be(0);

// Test MudPagination int base NavigateTo
int pagecount = (int)Math.Ceiling((double)(dataGrid.Instance.Items.Count() / dataGrid.Instance.RowsPerPage));
// navigate to the last page programmatically
await comp.InvokeAsync(() => dataGrid.Instance.NavigateTo(pagecount - 1));
dataGrid.Instance.CurrentPage.Should().Be(4);

// navigate to the previous page programmatically
await comp.InvokeAsync(() => dataGrid.Instance.NavigateTo(dataGrid.Instance.CurrentPage - 1));
dataGrid.Instance.CurrentPage.Should().Be(3);

// navigate back to the first page programmatically
await comp.InvokeAsync(() => dataGrid.Instance.NavigateTo(0));
dataGrid.Instance.CurrentPage.Should().Be(0);
}


Expand Down
11 changes: 11 additions & 0 deletions src/MudBlazor/Components/DataGrid/MudDataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,17 @@ public void NavigateTo(Page page)
GroupItems();
}

/// <summary>
/// Navigates to a specific page when the data grid has an attached MudPagination component.
/// </summary>
/// <param name="pageIndex">Index of the page to navigate to.</param>
public void NavigateTo(int pageIndex)
{
CurrentPage = Math.Min(Math.Max(0, pageIndex), numPages - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henon do you think we should allow this in v7 PRs to write directly to parameter in components that didn't migrate to ParamterState? Or we should kindly ask to migrate whole property to ParameterState + add new feature, but this would be quite some work as there are 22 references to CurrentPage property.

Copy link
Collaborator

@henon henon Apr 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we must request to use the state framework for new parameters that are manipulated or new API that will manipulate parameters in order to avoid the necessity for future breaking changes.

Because in this case with using the state framework it would have to be NavigateToAsync because you have to call await _currentPageState.SetValueAsync(...).


GroupItems();
}

/// <summary>
/// Sets the rows displayed per page when the data grid has an attached data pager.
/// </summary>
Expand Down