Skip to content

Commit

Permalink
MudDataGridPager: When no items, Pager now shows "0-0 of 0" (MudBlazo…
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoroz20 authored Jul 4, 2024
1 parent 9cc3dfa commit c81594e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@namespace MudBlazor.UnitTests.TestComponents

<MudDataGrid Items="@_items">
<Columns>
<PropertyColumn Property="x => x.Name" />
</Columns>
<PagerContent>
<MudDataGridPager PageSizeSelector="@PageSizeDropDown" />
</PagerContent>
</MudDataGrid>

@code {
[Parameter]
public bool PageSizeDropDown { get; set; } = true;

private List<Item> _items = new List<Item>();

public class Item
{
public string Name { get; set; }

public Item(string name)
{
Name = name;
}
}

}
11 changes: 11 additions & 0 deletions src/MudBlazor.UnitTests/Components/DataGridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,17 @@ public async Task DataGridPagingAllTest()
comp.FindAll(".mud-table-pagination-select")[^1].TextContent.Trim().Should().Be("All");
}

[Test]
public async Task DataGridPaginationNoItemsTest()
{
var comp = Context.RenderComponent<DataGridPaginationNoItemsTest>();
var dataGrid = comp.FindComponent<MudDataGrid<DataGridPaginationNoItemsTest.Item>>();
// check that the page size dropdown is shown
comp.FindComponents<MudSelect<int>>().Count.Should().Be(1);

dataGrid.FindAll(".mud-table-pagination-caption")[^1].TextContent.Trim().Should().Be("0-0 of 0");
}

[Test]
public void DataGridHideNavigationTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private string Info
if (DataGrid == null)
return "DataGrid==null";
Debug.Assert(DataGrid != null);
var firstItem = DataGrid.CurrentPage * DataGrid.RowsPerPage + 1;
var firstItem = DataGrid?.GetFilteredItemsCount() == 0 ? 0 : DataGrid.CurrentPage * DataGrid.RowsPerPage + 1;
var lastItem = Math.Min((DataGrid.CurrentPage + 1) * DataGrid.RowsPerPage, DataGrid.GetFilteredItemsCount());
var allItems = DataGrid?.GetFilteredItemsCount();
return InfoFormat.Replace("{first_item}", $"{firstItem}").Replace("{last_item}", $"{lastItem}").Replace("{all_items}", $"{allItems}");
Expand Down

0 comments on commit c81594e

Please sign in to comment.