问题
How to handle row selected changed event for a table using Blazor? I tried handling @onchange as well as @onselectionchange. The syntax for the table looks like this:
<table class="table" @onchange="@this.SelectionChanged">
回答1:
Your event binding doesn't work because the table
element does not emit change
events.
Instead, you could add an input element (for example a checkbox) inside your table rows. You can then handle row selection changes by adding your event binding to the input elements.
Read more on the HTMLElement change event in this article.
回答2:
You can use Onclick in the row:
<tbody>
@foreach (var item in Forecasts)
{
<tr class="@item.Clase" @onclick="@(() => DoSomething(item))">
<td>@item.Date</td>
<td>@item.TemperatureC</td>
<td>@item.TemperatureF</td>
<td>@item.Summary</td>
</tr>
}
</tbody>
and create a Dosomething to receive the item
来源:https://stackoverflow.com/questions/56908599/how-to-handle-table-row-selected-changed