Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.AspNetCore.Components.QuickGrid.QuickGrid<TGridItem>.RowClass.get -> System.Func<TGridItem, string?>?
Microsoft.AspNetCore.Components.QuickGrid.QuickGrid<TGridItem>.RowClass.set -> void
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@

private void RenderRow(RenderTreeBuilder __builder, int rowIndex, TGridItem item)
{
<tr @key="@(ItemKey(item))" aria-rowindex="@rowIndex">
var rowClass = RowClass?.Invoke(item) ?? null;
<tr @key="@(ItemKey(item))" aria-rowindex="@rowIndex" class="@rowClass">
@foreach (var col in _columns)
{
<td class="@ColumnClass(col)" @key="@col">@{ col.CellContent(__builder, item); }</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public partial class QuickGrid<TGridItem> : IAsyncDisposable
/// </summary>
[Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object>? AdditionalAttributes { get; set; }

/// <summary>
/// Optionally defines a class to be applied to a rendered row.
/// </summary>
[Parameter] public Func<TGridItem, string?>? RowClass { get; set; }

[Inject] private IServiceProvider Services { get; set; } = default!;
[Inject] private IJSRuntime JS { get; set; } = default!;

Expand Down
26 changes: 26 additions & 0 deletions src/Components/test/E2ETest/Tests/QuickGridTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,30 @@ public void AdditionalAttributesApplied()
Assert.Equal("somevalue", grid.GetDomAttribute("custom-attrib"));
Assert.Contains("custom-class-attrib", grid.GetDomAttribute("class")?.Split(" "));
}

[Fact]
public void RowClassApplied()
{
var grid = app.FindElement(By.CssSelector("#grid > table"));
var rows = grid.FindElements(By.CssSelector("tbody > tr"));

bool isJulieRowFound = false;
foreach (var row in rows)
{
var firstName = row.FindElement(By.CssSelector("td:nth-child(2)")).Text;
if (firstName == "Julie")
{
isJulieRowFound = true;
Assert.Equal("highlight", row.GetDomAttribute("class"));
}
else
{
Assert.Null(row.GetDomAttribute("class"));
}
}
if (!isJulieRowFound)
{
Assert.Fail("No row found for Julie to highlight.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<h3>Sample QuickGrid Component</h3>

<div id="grid">
<QuickGrid Items="@FilteredPeople" Pagination="@pagination" custom-attrib="somevalue" class="custom-class-attrib">
<QuickGrid Items="@FilteredPeople" Pagination="@pagination" RowClass="HighlightJulie" custom-attrib="somevalue" class="custom-class-attrib">
<PropertyColumn Property="@(p => p.PersonId)" Sortable="true" />
<PropertyColumn Property="@(p => p.firstName)" Sortable="true">
<ColumnOptions>
<div class="search-box">
<input type="search" autofocus @bind="firstNameFilter" @bind:event="oninput" placeholder="First name..." />
</div>
</ColumnOptions>
</PropertyColumn>
<ColumnOptions>
<div class="search-box">
<input type="search" autofocus @bind="firstNameFilter" @bind:event="oninput" placeholder="First name..." />
</div>
</ColumnOptions>
</PropertyColumn>
<PropertyColumn Property="@(p => p.lastName)" Sortable="true" />
<PropertyColumn Property="@(p => p.BirthDate)" Format="yyyy-MM-dd" Sortable="true" />
<PropertyColumn Title="Age in years" Property="@(p => ComputeAge(p.BirthDate))" Sortable="true"/>
Expand All @@ -27,6 +27,8 @@
int ComputeAge(DateOnly birthDate)
=> DateTime.Now.Year - birthDate.Year - (birthDate.DayOfYear < DateTime.Now.DayOfYear ? 0 : 1);

string HighlightJulie(Person person) => person.firstName == "Julie" ? "highlight" : null;

IQueryable<Person> FilteredPeople
{
get
Expand Down
Loading