Skip to content

Commit 72fc21a

Browse files
Copilotjaviercn
andcommitted
Add OnRowClick EventCallback to QuickGrid (#64606)
* Initial plan * Fix RowClassApplied test and consolidate RenderRow logic Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com> * Fix trailing space in combinedClass when rowClass is null Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
1 parent 5d57a3b commit 72fc21a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@
6666
private void RenderRow(RenderTreeBuilder __builder, int rowIndex, TGridItem item)
6767
{
6868
var rowClass = RowClass?.Invoke(item);
69+
var combinedClass = OnRowClick.HasDelegate
70+
? string.IsNullOrEmpty(rowClass) ? "row-clickable" : $"row-clickable {rowClass}"
71+
: rowClass;
72+
6973
if (OnRowClick.HasDelegate)
7074
{
71-
<tr @key="@(ItemKey(item))" aria-rowindex="@rowIndex" class="row-clickable @rowClass" @onclick="@(() => OnRowClick.InvokeAsync(item))">
75+
<tr @key="@(ItemKey(item))"
76+
aria-rowindex="@rowIndex"
77+
class="@combinedClass"
78+
@onclick="@(() => OnRowClick.InvokeAsync(item))">
7279
@foreach (var col in _columns)
7380
{
7481
<td class="@ColumnClass(col)" @key="@col">@{ col.CellContent(__builder, item); }</td>
@@ -77,7 +84,9 @@
7784
}
7885
else
7986
{
80-
<tr @key="@(ItemKey(item))" aria-rowindex="@rowIndex" class="@rowClass">
87+
<tr @key="@(ItemKey(item))"
88+
aria-rowindex="@rowIndex"
89+
class="@combinedClass">
8190
@foreach (var col in _columns)
8291
{
8392
<td class="@ColumnClass(col)" @key="@col">@{ col.CellContent(__builder, item); }</td>

src/Components/test/E2ETest/Tests/QuickGridTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ public void RowClassApplied()
136136
if (firstName == "Julie")
137137
{
138138
isJulieRowFound = true;
139-
Assert.Equal("highlight", row.GetDomAttribute("class"));
139+
Assert.Equal("row-clickable highlight", row.GetDomAttribute("class"));
140140
}
141141
else
142142
{
143-
Assert.Null(row.GetDomAttribute("class"));
143+
Assert.Equal("row-clickable", row.GetDomAttribute("class"));
144144
}
145145
}
146146

0 commit comments

Comments
 (0)