Skip to content
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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

MattyLeslie
Copy link
Contributor

@MattyLeslie MattyLeslie commented May 23, 2024

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:

  1. Introduced EventCallback Parameter
  2. Updated the RenderRow method to include an @onclick event handler that triggers the OnRowClicked callback.
  3. Modified the SampleQuickGridComponent to demonstrate the usage of the OnRowClicked event callback.
  4. Added E2E test to validify the changes using SampleQuickGridComponent

Fixes #44899

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label May 23, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 23, 2024
Copy link
Contributor

Thanks for your PR, @MattyLeslie. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@MattyLeslie MattyLeslie marked this pull request as ready for review May 23, 2024 13:04
@MattyLeslie MattyLeslie requested a review from a team as a code owner May 23, 2024 13:04
Copy link
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jun 3, 2024
@@ -19332,7 +19332,7 @@
},
"src/JSInterop/Microsoft.JSInterop.JS/src": {
"name": "@microsoft/dotnet-js-interop",
Copy link
Member

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>
Copy link
Member

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))">
Copy link
Member

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?

@SteveSandersonMS
Copy link
Member

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.

@MattyLeslie
Copy link
Contributor Author

MattyLeslie commented Jun 18, 2024

@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.

@MattyLeslie MattyLeslie marked this pull request as draft June 18, 2024 13:00
@MattyLeslie MattyLeslie marked this pull request as ready for review August 26, 2024 09:20
__builder.AddAttribute(2, "class", ColumnClass(col));
__builder.CloseElement();
}
__builder.CloseElement();
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QuickGrid: Add EventCallback<TGridItem> for clicking on a row.
2 participants