MudBlazor / MudBlazor

Blazor Component Library based on Material design with an emphasis on ease of use. Mainly written in C# with Javascript kept to a bare minimum it empowers .NET developers to easily debug it if needed.
http://mudblazor.com
MIT License
7.22k stars 1.18k forks source link

Update MudDataGrid to work with MudPagination #8821

Open digitaldirk opened 2 weeks ago

digitaldirk commented 2 weeks ago

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

MudDataGridMudPagination

Checklist

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ScarletKuro commented 2 weeks ago

Hi, thanks for PR.

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

digitaldirk commented 2 weeks ago

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.