-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QuickGrid: Add EventCallback<TGridItem> for clicking on a row. #55851
base: main
Are you sure you want to change the base?
QuickGrid: Add EventCallback<TGridItem> for clicking on a row. #55851
Conversation
…w click and invoke the event callback:
…icked can be bound to
Thanks for your PR, @MattyLeslie. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
@@ -19332,7 +19332,7 @@ | |||
}, | |||
"src/JSInterop/Microsoft.JSInterop.JS/src": { | |||
"name": "@microsoft/dotnet-js-interop", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert the changes to this file please? It's not involved in this PR.
<td class="@ColumnClass(col)" @key="@col">@{ col.CellContent(__builder, item); }</td> | ||
<td class="@ColumnClass(col)" @key="@col">@{ | ||
col.CellContent(__builder, item); | ||
}</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert unnecessary stylistic changes like this one.
private void RenderRow(RenderTreeBuilder __builder, int rowIndex, TGridItem item) | ||
{ | ||
<tr @key="@(ItemKey(item))" aria-rowindex="@rowIndex"> | ||
<tr @key="@(ItemKey(item))" aria-rowindex="@rowIndex" @onclick="@(async () => await HandleRowClick(item))"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's painful but unfortunately, for performance reasons, this is a case where we'd need to fall back on raw RenderTreeBuilder logic instead of using Razor syntax.
Having an @onclick
unconditionally like this means that (1) we're always doing several extra allocations per row even if you're not using this feature (because you're building a delegate regardless), and (2) we're always assigning and removing event IDs for every row even if you're not using this feature.
To avoid these problems, we'd need to change the RenderRow
method so that the outer <tr>
is constructed through a series of __builder.*
calls, with the "onclick" added inside an if (OnRowClicked.HasDelegage) { ... }
. The contents within that (i.e., the @foreach (var col in _columns)
and so on) can continue to be emitted using Razor syntax.
Does that make sense?
Thanks very much for submitting this, @MattyLeslie! Mostly what you've done looks great, and it's particularly good you added the E2E test. Hopefully we will be able to include this, though it just requires one main change for perf reasons since QuickGrid really tries hard to max out on perf whenever possible - see other comment. |
@SteveSandersonMS Thank you for the review! Really appreciate the detail. At first glance the feedback is making sense, I'll need a bit of time to make the changes. |
__builder.AddAttribute(2, "class", ColumnClass(col)); | ||
__builder.CloseElement(); | ||
} | ||
__builder.CloseElement(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify why you prefer to change the syntax from Razor to the underlying C# builder methods? I would have thought it's advantageous to use the shorter syntax as there's less risk of a mistake. For example here the @key
seems to have been lost, but it's a bit harder to see that from the diff than it would be if the Razor syntax was used.
Was it intentional to remove @key
?
QuickGrid: Add EventCallback for clicking on a row.
Description:
This pull request aims to enhance the QuickGrid component by adding the capability to handle row click events. This feature allows developers to perform specific actions when a user clicks on a row in the grid, such as navigating to a detailed view of the selected item.
Changes made:
EventCallback
ParameterRenderRow
method to include an@onclick
event handler that triggers theOnRowClicked
callback.SampleQuickGridComponent
to demonstrate the usage of theOnRowClicked
event callback.SampleQuickGridComponent
Fixes #44899