This is a migrated thread and some comments may be shown as answers.

OnRowClick equivalent?

4 Answers 267 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Ronald
Top achievements
Rank 1
Veteran
Ronald asked on 01 Apr 2021, 10:13 PM
If I select an item in a ListView is there any way I can get the whole row like for a Grid? If there were a Grid I would assign a function to be called OnRowClick. But that does not seem to be available for ListView?

4 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 05 Apr 2021, 04:28 PM

Hello Ronald,

The ListView, unlike the grid, does not control the rendering of its items, so it can't offer such an event to you. You can, however, hook your own events, like @onclick and get the item with a simple lambda.

You can find a very similar example in this project: https://github.com/telerik/blazor-ui/tree/master/listview/item-selection

 

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Ronald
Top achievements
Rank 1
Veteran
answered on 05 Apr 2021, 05:02 PM
One more question. Again forgive me but I am new. When forming the lambda, is there a way to pass in the whole row that was clicked on?
0
Ronald
Top achievements
Rank 1
Veteran
answered on 05 Apr 2021, 05:04 PM
Basically I want to pass in the whole context?
0
Accepted
Marin Bratanov
Telerik team
answered on 05 Apr 2021, 05:05 PM

Hello Ronald,

You can pass whatever object you choose to. I chose to pass an ID in the example for selection I made, you can pass the whole model, just touch up the corresponding method signature to accept that.

The basics would look something like:

<TelerikListView Data="@ListViewData" Width="700px" Pageable="true">
    <HeaderTemplate>
        <h2>Employee List</h2>
    </HeaderTemplate>
    <Template>
        <div class="listview-item @( context.Selected ? "selected-item" : "" )" @onclick="@( _ => Console.WriteLine(context) )">
            <h4>@context.Date.ToShortDateString()</h4>
            <h5>@context.TemperatureC &deg;C</h5>
            <h6>@context.Summary</h6>
        </div>
    </Template>
</TelerikListView>

Regards,
Marin Bratanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ListView
Asked by
Ronald
Top achievements
Rank 1
Veteran
Answers by
Marin Bratanov
Telerik team
Ronald
Top achievements
Rank 1
Veteran
Share this question
or