How to handle Table row selected changed?

前端 未结 2 1114
清酒与你
清酒与你 2021-01-29 05:26

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:

相关标签:
2条回答
  • 2021-01-29 06:07

    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

    0 讨论(0)
  • 2021-01-29 06:15

    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.

    0 讨论(0)
提交回复
热议问题