How to handle Table row selected changed?

自古美人都是妖i 提交于 2020-11-29 19:06:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!