Skip to content

Commit 2810603

Browse files
docs(grid): better SelectedItemsChanged event example for single selection
1 parent 309da5d commit 2810603

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

components/grid/selection/single.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,38 @@ You can add a checkbox column for single selection. It is required if the `InCel
8585

8686
You can respond to the user action of selecting a new item through the `SelectedItemsChanged` event.
8787

88+
The example below shows how to handle the `SelectedItemsChanged` event to extract information about the selected item and use it to populate a second grid with details about the selected record.
89+
8890
>caption Single Selection and handling the SelectedItemsChanged event
8991
9092
````CSHTML
9193
@using Telerik.Blazor.Components.Grid
92-
93-
@if (SelectedEmployee != null)
94-
{
95-
<span>Selected Employee: @SelectedEmployee.Name </span>
96-
}
94+
@using Telerik.Blazor
9795
9896
<TelerikGrid Data=@GridData
9997
SelectionMode="GridSelectionMode.Single"
10098
SelectedItemsChanged="@((IEnumerable<Employee> employeeList) => OnSelect(employeeList))"
10199
Pageable="true"
102-
Height="400px">
100+
Height="300px">
103101
<TelerikGridColumns>
104102
<TelerikGridColumn Field=@nameof(Employee.Name) />
105103
<TelerikGridColumn Field=@nameof(Employee.Team) Title="Team" />
106104
</TelerikGridColumns>
107105
</TelerikGrid>
108106
107+
@if (TeamMatesList != null)
108+
{
109+
<h6>@SelectedEmployee.Team</h6>
110+
<TelerikGrid Data="@TeamMatesList">
111+
<TelerikGridColumns>
112+
<TelerikGridColumn Field=@nameof(Employee.Name) />
113+
</TelerikGridColumns>
114+
</TelerikGrid>
115+
}
116+
109117
@code {
110118
public List<Employee> GridData { get; set; }
119+
public List<Employee> TeamMatesList { get; set; }
111120
public Employee SelectedEmployee { get; set; }
112121
113122
protected override void OnInitialized()
@@ -124,9 +133,18 @@ You can respond to the user action of selecting a new item through the `Selected
124133
}
125134
}
126135
127-
protected void OnSelect(IEnumerable<Employee> employees)
136+
protected async Task OnSelect(IEnumerable<Employee> employees)
128137
{
129138
SelectedEmployee = employees.FirstOrDefault();
139+
//with single row selection, there is only one item in the collection
140+
141+
//fetch actual data for the child grid here. This example filters the original data for brevity
142+
if(TeamMatesList == null)
143+
{
144+
TeamMatesList = new List<Employee>();
145+
}
146+
TeamMatesList.Clear();
147+
TeamMatesList = GridData.Where(empl => empl.Team == SelectedEmployee.Team).ToList();
130148
}
131149
132150
public class Employee

0 commit comments

Comments
 (0)