diff --git a/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/PublicAPI.Unshipped.txt b/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/PublicAPI.Unshipped.txt index 7dc5c58110bf..d93f10f53809 100644 --- a/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/PublicAPI.Unshipped.txt +++ b/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +Microsoft.AspNetCore.Components.QuickGrid.QuickGrid.RowClass.get -> System.Func? +Microsoft.AspNetCore.Components.QuickGrid.QuickGrid.RowClass.set -> void diff --git a/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor b/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor index f1fce0c434ce..cc8f64423eae 100644 --- a/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor +++ b/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor @@ -65,7 +65,8 @@ private void RenderRow(RenderTreeBuilder __builder, int rowIndex, TGridItem item) { - + var rowClass = RowClass?.Invoke(item); + @foreach (var col in _columns) { @{ col.CellContent(__builder, item); } diff --git a/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor.cs b/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor.cs index 3edf9b93c740..859a974f0207 100644 --- a/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor.cs +++ b/src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor.cs @@ -104,6 +104,11 @@ public partial class QuickGrid : IAsyncDisposable /// [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary? AdditionalAttributes { get; set; } + /// + /// Optional. A callback to be invoked for each rendered row to specify a CSS class. + /// + [Parameter] public Func? RowClass { get; set; } + [Inject] private IServiceProvider Services { get; set; } = default!; [Inject] private IJSRuntime JS { get; set; } = default!; diff --git a/src/Components/test/E2ETest/Tests/QuickGridTest.cs b/src/Components/test/E2ETest/Tests/QuickGridTest.cs index 71a7d452648d..02e50484092b 100644 --- a/src/Components/test/E2ETest/Tests/QuickGridTest.cs +++ b/src/Components/test/E2ETest/Tests/QuickGridTest.cs @@ -121,4 +121,31 @@ 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."); + } + } } diff --git a/src/Components/test/testassets/BasicTestApp/QuickGridTest/SampleQuickGridComponent.razor b/src/Components/test/testassets/BasicTestApp/QuickGridTest/SampleQuickGridComponent.razor index ad76551bae3b..5a685737ff5b 100644 --- a/src/Components/test/testassets/BasicTestApp/QuickGridTest/SampleQuickGridComponent.razor +++ b/src/Components/test/testassets/BasicTestApp/QuickGridTest/SampleQuickGridComponent.razor @@ -3,15 +3,15 @@

Sample QuickGrid Component

- + - - - - + + + + @@ -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 FilteredPeople { get