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

Conversation

digitaldirk
Copy link
Contributor

@digitaldirk digitaldirk commented Apr 26, 2024

Description

MudDataGrid only had a Page (last, next, first,...) based NavigateTo method. Added a int based NavigateTo method so the MudPagination component can be used with the MudDataGrid component. Inspired by the MudTableBase.cs version. Resolves #8819

How Has This Been Tested?

Visually tested with docs project, and added unit tests.

Used this code:

<MudDataGrid @ref="@_table" Items="@Elements.Take(40)">
    <Columns>
        <PropertyColumn Property="x => x.Number" Title="Nr" />
        <PropertyColumn Property="x => x.Sign" />
        <PropertyColumn Property="x => x.Name" />
        <PropertyColumn Property="x => x.Position" />
        <PropertyColumn Property="x => x.Molar" Title="Molar mass" />
    </Columns>
  <PagerContent>
    <MudPagination SelectedChanged="PageChanged" Count="@((_table.GetFilteredItemsCount() + _table.RowsPerPage - 1) / _table.RowsPerPage)" Class="pa-4" />
  </PagerContent>
</MudDataGrid>

@code { 
  private MudDataGrid<Element> _table;

    private IEnumerable<Element> Elements = new List<Element>();

    protected override async Task OnInitializedAsync()
    {
        Elements = await httpClient.GetFromJsonAsync<List<Element>>("webapi/periodictable");
    }

  private void PageChanged(int i)
  {
    _table.NavigateTo(i - 1);
  }
}

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

MudDataGridMudPagination

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

MudDataGrid only had a Page (last, next, first,...) based NavigateTo method. Added a int based NavigateTo. Inspired by the MudTableBase version.
@github-actions github-actions bot added enhancement New feature or request PR: needs review labels Apr 26, 2024
Copy link

codecov bot commented Apr 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.14%. Comparing base (28bc599) to head (88c09ed).
Report is 127 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8821      +/-   ##
==========================================
+ Coverage   89.82%   90.14%   +0.31%     
==========================================
  Files         412      421       +9     
  Lines       11878    12216     +338     
  Branches     2364     2409      +45     
==========================================
+ Hits        10670    11012     +342     
+ Misses        681      663      -18     
- Partials      527      541      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ScarletKuro
Copy link
Member

Hi, thanks for PR.

It's required to add a bUnit test for this feature.

/// <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(...).

Added tests for int based NavigateTo method
@digitaldirk
Copy link
Contributor Author

It's required to add a bUnit test for this feature.

@ScarletKuro Added tests to the existing DataGridPaginationTest method. I did not add a MudPagination component to the DataGridPaginationTest test component but I thought that was fine, please let me know if not.

Copy link
Contributor

@tjscience tjscience left a comment

Choose a reason for hiding this comment

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

This looks good to me. Thanks for the addition, @digitaldirk!

Copy link
Collaborator

@henon henon left a comment

Choose a reason for hiding this comment

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

@digitaldirk can you please read CONTRIBUTING.md so you know what we are talking about? If you then have questions we'll answer and help.

Please register parameter CurrentPage using our new state framework and avoid writing to the parameter by modifying the _currentPageState object instead. In the unit test, it depends on whether or not CurrentPage is two-way bound. If so it can remain as it is. If not you'll have to use GetState<int>(nameof(CurrentPage)) to get the value of CurrentPage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants