Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a9f15b7

Browse files
NansiYanchevayordan-mitevdimodi
authoredAug 2, 2024
docs(grid): Add Cell Selection documentation and revamp Selection articles (#2211)
* docs(Grid):Add cell selection to overview article. Revamp Selection in Template and add related KB. * draft revamp of overview selection page * draft the selection overview page * docs(Grid): Revamp selection overview. Add Row Selection. * add rows selection examples * docs(Grid): revamp selection and other grid features * docs(Grid): draft cell selection article * docs(Grid): update events article * docs(Grid): update cell selection article * docs(Grid): work on selection and templates * docs(Grid): update rows and overview articles * docs(Grid): finalize rows selection article * docs(Grid): update cells,overview and rows * docs(Grid): finalize cell article update overview and row * docs(Grid): handle redirection * docs(Grid): rename data type * Update components/grid/selection/cells.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/cells.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/cells.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/overview.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/rows.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/overview.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/rows.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/rows.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/rows.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/rows.md Co-authored-by: Yordan <[email protected]> * Update components/grid/selection/rows.md Co-authored-by: Yordan <[email protected]> * Update knowledge-base/grid-row-selection-in-column-template.md Co-authored-by: Yordan <[email protected]> * Update knowledge-base/grid-row-selection-in-column-template.md Co-authored-by: Yordan <[email protected]> * Update knowledge-base/grid-row-selection-in-column-template.md Co-authored-by: Yordan <[email protected]> * Update knowledge-base/grid-row-selection-in-column-template.md Co-authored-by: Yordan <[email protected]> * Update knowledge-base/grid-row-selection-in-column-template.md Co-authored-by: Yordan <[email protected]> * Update components/grid/overview.md Co-authored-by: Yordan <[email protected]> * docs(Grid): update after review * Update components/grid/selection/cells.md Co-authored-by: Dimo Dimov <[email protected]> * Update components/grid/selection/overview.md Co-authored-by: Dimo Dimov <[email protected]> * Update components/grid/selection/overview.md Co-authored-by: Dimo Dimov <[email protected]> * Update components/grid/selection/overview.md Co-authored-by: Dimo Dimov <[email protected]> * docs(Grid): update after review * docs(grid): Overview and Row Selection revamp * docs(treelist): Remove Cell selection draft * docs(grid): Revamp Cell Selection article --------- Co-authored-by: Yordan <[email protected]> Co-authored-by: Dimo Dimov <[email protected]>
1 parent 65af173 commit a9f15b7

19 files changed

+604
-687
lines changed
 

‎components/grid/columns/auto-generated.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,5 +384,5 @@ This example shows how to:
384384
## See also
385385
* [Column Width]({%slug grid-columns-width%})
386386
* [Live Demo: Auto Generated Columns](https://demos.telerik.com/blazor-ui/grid/column-auto-generation)
387-
* [Selection]({%slug components/grid/selection/overview%})
387+
* [Selection]({%slug grid-selection-overview%})
388388
* [Paging]({%slug components/grid/features/paging%})

‎components/grid/columns/checkbox.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ position: 2
1212

1313
This article describes the configuration parameters of the Blazor `GridCheckboxColumn`.
1414

15-
The `GridCheckboxColumn` provides an additional way for users to [select Grid rows]({%slug components/grid/selection/overview%}). By default, users can select and unselect rows by clicking anywhere on them.
15+
The `GridCheckboxColumn` provides an additional way for users to [select Grid rows]({%slug grid-selection-overview%}). By default, users can select and unselect rows by clicking anywhere on them.
1616

1717
If you need checkboxes to display or edit boolean values, then use a [Grid column template]({%slug grid-templates-column%}) instead.
1818

@@ -25,7 +25,7 @@ The Grid checkbox column has the following exclusive parameters. For other avail
2525
| Parameter | Type and Default&nbsp;Value | Description |
2626
| --- | --- | --- |
2727
| `CheckBoxOnlySelection` | `bool` | Determines if row selection occurs only on checkbox clicks. By default, user can select rows by clicking anywhere, except on command buttons. |
28-
| `SelectAll` | `bool` <br /> (`true`) | Determines if the column header renders a checkbox to select all rows. Set this to `false` if the [Grid `SelectionMode` is `Single`]({%slug components/grid/selection/single%}). The `SelectAll` parameter has no effect when the checkbox column has a [`HeaderTemplate`](#headertemplate). |
28+
| `SelectAll` | `bool` <br /> (`true`) | Determines if the column header renders a checkbox to select all rows. Set this to `false` if the [Grid `SelectionMode` is `Single`]({%slug grid-selection-overview%}#use-single-or-multiple-selection). The `SelectAll` parameter has no effect when the checkbox column has a [`HeaderTemplate`](#headertemplate). |
2929
| `SelectAllMode` | `GridSelectAllMode` enum <br /> (`Current`) | Determines if the header cell checkbox selects all rows on the current page, or all rows in the Grid. `Current` selects the visible rows on the current page. `All` selects all the data items, including ones that may be currently filtered out. `All` requires the [Grid to be data-bound via its `Data` parameter, and not `OnRead`]({%slug common-features-data-binding-overview%}#how-to-provide-data). When using `OnRead`, the two `SelectAllMode`s behave identically, because the Grid controls only one page of items. |
3030
| `Title` | `string` | The text in the checkbox column's header. The title renders only when `SelectAll` is `false`. |
3131

@@ -185,4 +185,4 @@ The example below doesn't take into account sorting, filtering and paging. If th
185185
## See Also
186186

187187
* [Live Demo: Grid Selection](https://demos.telerik.com/blazor-ui/grid/selection)
188-
* [Grid Selection Overview]({%slug components/grid/selection/overview%})
188+
* [Grid Selection Overview]({%slug grid-selection-overview%})

‎components/grid/editing/incell.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Click a cell, edit it and click outside of the grid to see the change. You can a
209209

210210
## Incell Editing and Selection
211211

212-
* To enable item selection with InCell Edit Mode, add a `<GridCheckboxColumn />` to the `<Columns>` collection. More information on that can be read in the [Selection]({%slug components/grid/selection/overview%}#notes) article.
212+
* To enable row selection with InCell Edit Mode, add a `<GridCheckboxColumn />` to the `<Columns>` collection. More information on that can be read in the [Row Selection]({%slug grid-selection-row%}#selection-and-editing-modes) article.
213213

214214
* To see how to select the row that is being edited in InCell edit mode without using a `<GridCheckboxColumn />` check out the [Row Selection in Edit with InCell EditMode]({%slug grid-kb-row-select-incell-edit%}) Knowledge Base article.
215215

@@ -238,4 +238,4 @@ The incell editor template requires a focusable element to maintain the tab orde
238238
## See Also
239239

240240
* [Live Demo: Grid InCell Editing](https://demos.telerik.com/blazor-ui/grid/editing-incell)
241-
* [Grid Selection Documentation]({%slug components/grid/selection/overview%})
241+
* [Grid Selection Documentation]({%slug grid-selection-overview%})

‎components/grid/events.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This article explains the events available in the Telerik Grid for Blazor. They
2929
* [PageChanged](#pagechanged)
3030
* [PageSizeChanged](#pagesizechanged)
3131
* [SelectedItemsChanged](#selecteditemschanged)
32+
* [SelectedCellsChanged](#selectedcellschanged)
3233

3334
## CUD Events
3435

@@ -1055,7 +1056,11 @@ Make sure to update the current page size when using the event.
10551056

10561057
## SelectedItemsChanged
10571058

1058-
Fires when item selection is enabled and the user [selects or deselects one item]({%slug components/grid/selection/single%}#selecteditemschanged-event) or [multiple items]({%slug components/grid/selection/multiple%}#selecteditemschanged-event), depending on the [selection mode]({%slug components/grid/selection/overview%}).
1059+
Fires when [row selection is enabled]({%slug grid-selection-overview%}#enable-row-or-cell-selection) and the user selects or deselects one row or multiple rows, depending on the [selection mode]({%slug grid-selection-overview%}#use-single-or-multiple-selection).
1060+
1061+
## SelectedCellsChanged
1062+
1063+
Fires when [cell selection is enabled]({%slug grid-selection-overview%}#enable-row-or-cell-selection) and the user selects or deselects one cell or multiple cells, depending on the [selection mode]({%slug grid-selection-overview%}#use-single-or-multiple-selection).
10591064

10601065
## See Also
10611066

‎components/grid/overview.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ The Grid supports custom content in various parts of the component such as data
144144

145145
## More Blazor Grid Features
146146

147-
* [Selection]({%slug components/grid/selection/overview%}) - select one or multiple rows via clicks or checkboxes
148-
* [State]({%slug grid-state%}) - get or set the Grid configuration programmatically
149-
* [Toolbar]({%slug components/grid/features/toolbar%}) - define user actions in a toolbar above the header cells
150-
* [Hierarchy]({%slug components/grid/features/hierarchy%}) - nest Grids and visualize parent-child relations between data records
151-
* [Drag and drop rows]({%slug grid-drag-drop-overview%}) - move rows in a Grid or between different Grids
152-
* [Loading animation]({%slug grid-loading%}) - show a loading animation to improve user experience during long data operations
153-
* Scrolling - the Grid will show standard scrollbars automatically if the data does not fit the current component width and height.
147+
* [Selection]({%slug grid-selection-overview%})select one or multiple rows through clicks or checkboxes or select one or multiple cells through clicks.
148+
* [State]({%slug grid-state%})get or set the Grid configuration programmatically.
149+
* [Toolbar]({%slug components/grid/features/toolbar%})define user actions in a toolbar above the header cells.
150+
* [Hierarchy]({%slug components/grid/features/hierarchy%})nest Grids and visualize parent-child relations between data records.
151+
* [Drag and drop rows]({%slug grid-drag-drop-overview%})move rows in a Grid or between different Grids.
152+
* [Loading animation]({%slug grid-loading%})show a loading animation to improve user experience during long data operations.
153+
* Scrollingthe Grid will show standard scrollbars automatically if the data does not fit the current component width and height.
154154

155155

156156
## Grid Parameters

‎components/grid/row-drag-drop.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ public class Resource
16911691

16921692
### Drag and Drop multiple Rows
16931693

1694-
You can drag and drop multiple rows in one or between multiple instances of the Grid. To enable it, you should set the [`SelectionMode` parameter]({%slug components/grid/selection/overview%}) of the TelerikGrid to `GridSelectionMode.Multiple`. Then, if you drag a selected row, you will effectively drag all the selected rows.
1694+
You can drag and drop multiple rows in one or between multiple instances of the Grid. To enable it, you should set the [`SelectionMode` parameter]({%slug grid-selection-overview%}) of the TelerikGrid to `GridSelectionMode.Multiple`. Then, if you drag a selected row, you will effectively drag all the selected rows.
16951695

16961696
When you select multiple rows, the row drag clue will be `N items selected` where `N` is the number of selected rows.
16971697

‎components/grid/selection/cells.md‎

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
---
2+
title: Cell Selection
3+
page_title: Grid - Cells Selection
4+
description: Learn how to select cell in Blazor Grid component. Explore the selected cells. Discover cell selection bevahior when combined with other Grid features. Try the practical sample code for cell selection.
5+
slug: grid-selection-cell
6+
tags: telerik,blazor,grid,selection,cells
7+
position: 5
8+
---
9+
10+
# Cell Selection
11+
12+
The Grid component supports [single or multiple cell selection]({%slug grid-selection-overview%}#use-single-or-multiple-selection). You can select a cell with mouse click anywhere in the cell. You can access the collection of selected cells, use this collection and manipulate it. You can subscribe to selection events.
13+
14+
## Basics
15+
16+
To select a cell, click anywhere in it.
17+
18+
To select a range of cells in one or more columns, hold the **Shift** key, while clicking on the first and last cell of the range. To select or deselect multiple cells that don't belong to a range, hold the **Ctrl** key.
19+
20+
You can also select a cell range by holding and dragging the mouse cursor. The dragging motion defines the diagonal of a rectangle and the Grid will select the cells under this rectangle. To allow this kind of cell selection, set the `DragToSelect` parameter in [`GridSelectionSettings`]({%slug grid-selection-overview%}#enable-row-or-cell-selection). The **Shift** and **Ctrl** modifiers are not supported in drag-to-select mode.
21+
22+
To enable cell selection:
23+
24+
1. Set the Grid `SelectedCells` parameter to a collection of type `IEnumerable<GridSelectedCellDescriptor>`. The collection must be initialized in advance. See [`GridSelectedCellDescriptor`](#gridselectedcelldescriptor) for infomation about the object properties.
25+
1. Add a `<GridSelectionSettings>` tag to the `<GridSettings>` tag, and set the `SelectionType` parameter to the `GridSelectionType.Cell`.
26+
27+
>caption Grid multiple cell selection
28+
29+
````CSHTML
30+
<TelerikGrid Data="@GridData"
31+
SelectionMode="@GridSelectionMode.Multiple"
32+
@bind-SelectedCells="@SelectedCells"
33+
Pageable="true">
34+
<GridSettings>
35+
<GridSelectionSettings SelectionType="@GridSelectionType.Cell" DragToSelect="true" />
36+
</GridSettings>
37+
<GridColumns>
38+
<GridColumn Field="@nameof(Employee.Name)" />
39+
<GridColumn Field="@nameof(Employee.Team)" />
40+
</GridColumns>
41+
</TelerikGrid>
42+
43+
<h3>Selected Cells:</h3>
44+
45+
<ul>
46+
@foreach (GridSelectedCellDescriptor cellDescriptor in SelectedCells)
47+
{
48+
<li>
49+
Column <code>Field</code>: @cellDescriptor.ColumnField,
50+
<code>EmployeeId</code>: @( ((Employee)cellDescriptor.DataItem).EmployeeId )
51+
</li>
52+
}
53+
</ul>
54+
55+
@code {
56+
private List<Employee> GridData { get; set; } = new();
57+
58+
private IEnumerable<GridSelectedCellDescriptor> SelectedCells { get; set; } = Enumerable.Empty<GridSelectedCellDescriptor>();
59+
60+
protected override void OnInitialized()
61+
{
62+
for (int i = 1; i <= 15; i++)
63+
{
64+
GridData.Add(new Employee()
65+
{
66+
EmployeeId = i,
67+
Name = $"Employee {i}",
68+
Team = $"Team {i % 3 + 1}"
69+
});
70+
}
71+
72+
SelectedCells = new List<GridSelectedCellDescriptor>() {
73+
new GridSelectedCellDescriptor()
74+
{
75+
DataItem = GridData.ElementAt(2),
76+
ColumnField = nameof(Employee.Name)
77+
}
78+
};
79+
}
80+
81+
public class Employee
82+
{
83+
public int EmployeeId { get; set; }
84+
public string Name { get; set; } = string.Empty;
85+
public string Team { get; set; } = string.Empty;
86+
}
87+
}
88+
````
89+
90+
## SelectedCellsChanged Event
91+
92+
You can respond to user selection actions through the `SelectedCellsChanged` event. The event handler receives a collection of type `IEnumerable<GridSelectedCellDescriptor>`. The collection may have multiple, single, or no objects in it, depending on the `SelectionMode` and the last user selection.
93+
94+
>caption Using the Grid SelectedCellsChanged event
95+
96+
````CSHTML
97+
@* Select cells and handle the SelectedCellsChanged event *@
98+
99+
<TelerikGrid Data="@GridData"
100+
SelectionMode="@GridSelectionMode.Multiple"
101+
SelectedCells="@SelectedCells"
102+
SelectedCellsChanged="@( (IEnumerable<GridSelectedCellDescriptor> newSelected) => OnCellSelect(newSelected) )"
103+
Pageable="true">
104+
<GridSettings>
105+
<GridSelectionSettings SelectionType="@GridSelectionType.Cell" DragToSelect="true" />
106+
</GridSettings>
107+
<GridColumns>
108+
<GridColumn Field="@nameof(Employee.Name)" />
109+
<GridColumn Field="@nameof(Employee.Team)" />
110+
</GridColumns>
111+
</TelerikGrid>
112+
113+
<p><code>SelectedItemsChanged</code> fired at: @SelectedCellsChangedLog</p>
114+
115+
<h3>Selected Cells:</h3>
116+
117+
<ul>
118+
@foreach (GridSelectedCellDescriptor cellDescriptor in SelectedCells)
119+
{
120+
<li>
121+
Column <code>Field</code>: @cellDescriptor.ColumnField,
122+
<code>EmployeeId</code>: @( ((Employee)cellDescriptor.DataItem).EmployeeId )
123+
</li>
124+
}
125+
</ul>
126+
127+
@code {
128+
private List<Employee> GridData { get; set; } = new();
129+
130+
private IEnumerable<GridSelectedCellDescriptor> SelectedCells { get; set; } = Enumerable.Empty<GridSelectedCellDescriptor>();
131+
132+
private string SelectedCellsChangedLog { get; set; } = string.Empty;
133+
134+
protected void OnCellSelect(IEnumerable<GridSelectedCellDescriptor> cellDescriptors)
135+
{
136+
// Update the SelectedCells collection manually.
137+
// When using two-way binding, this happens automatically.
138+
SelectedCells = cellDescriptors;
139+
140+
SelectedCellsChangedLog = DateTime.Now.ToLongTimeString();
141+
}
142+
143+
protected override void OnInitialized()
144+
{
145+
for (int i = 1; i <= 15; i++)
146+
{
147+
GridData.Add(new Employee()
148+
{
149+
EmployeeId = i,
150+
Name = $"Employee {i}",
151+
Team = $"Team {i % 3 + 1}"
152+
});
153+
}
154+
155+
SelectedCells = new List<GridSelectedCellDescriptor>() {
156+
new GridSelectedCellDescriptor()
157+
{
158+
DataItem = GridData.ElementAt(2),
159+
ColumnField = nameof(Employee.Name)
160+
}
161+
};
162+
}
163+
164+
public class Employee
165+
{
166+
public int EmployeeId { get; set; }
167+
public string Name { get; set; } = string.Empty;
168+
public string Team { get; set; } = string.Empty;
169+
}
170+
}
171+
````
172+
173+
### SelectedCellsChanged and Asynchronous Operations
174+
175+
The `SelectedCellsChanged` event handler cannot be awaited. To execute asynchronous operations when the user selects rows, use the [`OnRowClick`]({%slug grid-events%}#onrowclick) or [`OnRowDoubleClick`]({%slug grid-events%}#onrowdoubleclick) event instead.
176+
177+
## GridSelectedCellDescriptor
178+
179+
The `GridSelectedCellDescriptor` type exposes the following properties:
180+
181+
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout)
182+
183+
| Property Name | Type | Description |
184+
| --- | --- | --- |
185+
| `ColumnField` | `string` | The value of the [Grid column `Field`]({%slug components/grid/columns/bound%}#data-binding) parameter, if set. |
186+
| `ColumnId` | `string` | The value of the [Grid column `Id`]({%slug components/grid/columns/bound%}#identification) parameter, if set. |
187+
| `DataItem` | `object` | The Grid data item instance. Cast it to the actual Grid model type before use. |
188+
189+
## Selection When Data Changes
190+
191+
When the Grid `Data` collection changes, the `SelectedCells` collection has the following behavior:
192+
193+
* When the user updates a selected cell and the item instance is replaced, you have to also replace the `SelectedCellDescriptor.DataItem` object in the `SelectedCells` collection. Do that in the [Grid `OnUpdate` event]({%slug components/grid/editing/overview%}#events).
194+
* When the user deletes a row with selected cells, update the `SelectedCells` collection in the the Grid `OnDelete` event handler.
195+
* To select cells from a new item in the Grid you can use the [`OnCreate` event]({%slug components/grid/editing/overview%}#events) to update the `SelectedCells` collection.
196+
197+
### Equals Comparison
198+
199+
The items in `SelectedCells` are compared against the items in the Grid data in order to determine which cells will be highlighted. The default framework behavior is to compare objects by reference. The data item references may not match when:
200+
201+
* The Grid is databound through its `OnRead` event and each data request returns different data item instances.
202+
* The `SelectedCells` are obtained from a different data source than the all Grid items, for example, from a separate service.
203+
204+
In such cases, the selected cells may not appear as expected. You have to [override the `Equals` method of the Grid model class]({%slug grid-state%}#equals-comparison) so that the items are compared by a unique identifier rather than by reference. When you override `Equals`, it is also recommended to override the [`GetHashCode`](https://docs.microsoft.com/en-us/dotnet/api/system.object.gethashcode) method.
205+
206+
## Cell Selection and Other Grid Features
207+
208+
The selection feature behavior may vary when the Grid configuration combines cell selection and other Grid features, such as editing, virtualization, paging, templates. In such cases you need to consider certain limitation or include some modications.
209+
210+
### Selection and Editing Modes
211+
212+
When you want to edit a Grid item, the cell selection has the following behavior:
213+
214+
* Cell selection is not supported with [`Incell` edit mode]({%slug components/grid/editing/incell%}) due to the overlapping pointer events that trigger selection and editing. If both features are enabled, only the editing will work.
215+
* [`Inline` edit mode]({%slug components/grid/editing/inline%}) and [`Popup` edit mode]({%slug components/grid/editing/popup%}) integrate with cell selection without limitations.
216+
217+
### Selection and Virtual Scrolling
218+
219+
When the Grid has [virtual scrolling]({%slug components/grid/virtual-scrolling%}), the component is able to select a range of cells with **Shift** only if all rows in that range are currently rendered. Consider the following scenario:
220+
221+
1. Select a cell.
222+
1. Scroll down, so that virtualization kicks in and the rendered rows are no longer the same.
223+
1. Select another cell with **Shift**.
224+
225+
In this case, the range selection will start from the first row that is currently rendered. Compare with [Selection and paging](#selection-and-paging) below.
226+
227+
### Selection and Paging
228+
229+
The `SelectedCells` collection persists across paging.
230+
231+
### Selection and Templates
232+
233+
When using [Grid templates]({%slug components/grid/features/templates%}) with cell selection:
234+
235+
* If you are using a [Grid column template]({%slug grid-templates-column%}) and you have a clickable element in the template, wrap this element in a container with a `@onclick:stopPropagation` directive. You can check the knowledge base article on [how to prevent row selection when the user clicks another component in the Grid column template]({%slug grid-kb-row-selection-in-column-template%}). It applies for both row and cell selection.
236+
* If you are using a [row template]({%slug components/grid/features/templates%}#row-template) the Grid does not support cell selection. The row template removes the built-in cell instances and the HTML markup may not even include the expected number of cells.
237+
238+
## See Also
239+
240+
* [Live Demo: Grid Cell Selection](https://demos.telerik.com/blazor-ui/grid/cell-selection)

‎components/grid/selection/multiple.md‎

Lines changed: 0 additions & 241 deletions
This file was deleted.

‎components/grid/selection/overview.md‎

Lines changed: 36 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -2,204 +2,68 @@
22
title: Overview
33
page_title: Grid - Selection Overview
44
description: Selection basics in the Grid for Blazor.
5-
slug: components/grid/selection/overview
5+
slug: grid-selection-overview
66
tags: telerik,blazor,grid,selection,overview
77
published: True
88
position: 0
99
---
1010

1111
# Grid Selection
1212

13-
The Grid component offers support for row selection.
14-
15-
In this article:
16-
17-
* [Selection Basics](#selection-basics)
18-
* [Example - Enable Row Selection](#example---enable-row-selection)
19-
* [Example - Select rows with checkboxes only](#example---select-rows-with-checkboxes-only)
20-
* [Notes](#notes)
21-
* [Editing Modes](#editing-modes)
22-
* [Selection in Template](#selection-in-template)
23-
* [Asynchronous Operations](#asynchronous-operations)
24-
* [SelectedItems Equals Comparison](#selecteditems-equals-comparison)
25-
* [Handle Data Changes](#handle-data-changes)
26-
* [Selection in Grid with virtualized rows](#selection-in-grid-with-virtualized-rows)
27-
* [Row Drag and Drop](#row-drag-and-drop)
28-
29-
30-
## Selection Basics
31-
32-
You can configure the selection behavior by setting `SelectionMode` to a member of the `Telerik.Blazor.GridSelectionMode` enum. The row selection can be:
33-
34-
* `None` - (the default value) to disable row selection
35-
* [Single]({%slug components/grid/selection/single%})
36-
* [Multiple]({%slug components/grid/selection/multiple%})
37-
38-
To select a row, click on it. To select multiple rows, hold down the `Ctrl` or `Shift` key to extend the selection.
39-
40-
You can also use a checkbox column to select rows. To use it, add a [`GridCheckboxColumn`]({%slug components/grid/columns/checkbox%}) in the `GridColumns` collection of the grid. It works with both selection modes. With multiple selection mode, the checkbox column offers [additional functionality]({%slug components/grid/selection/multiple%}#checkbox-selection).
41-
42-
You can get or set the selected items through the `SelectedItems` property. It is a collection of items from the Grid's `Data`.
43-
44-
The [single selection]({%slug components/grid/selection/single%}) and [multiple selection]({%slug components/grid/selection/multiple%}) articles provide more examples and details on using the grid features.
45-
46-
### Example - Enable Row Selection
47-
48-
````CSHTML
49-
See how the row selection modes work
13+
The Grid component supports row and cell selection. When you select a row or a cell, they will be highlighted in the Grid. This article provides an overview of the Grid selection behavior and configuration:
5014

51-
<select @bind=@selectionMode>
52-
<option value=@GridSelectionMode.Single>Single</option>
53-
<option value=@GridSelectionMode.Multiple>Multiple</option>
54-
</select>
15+
* [Enable row or cell selection](#enable-row-or-cell-selection)
16+
* [Use single or multiple selection](#use-single-or-multiple-selection)
17+
* [Access selected rows or cells](#access-selected-rows-or-cells)
18+
* [Handle selection events](#events)
19+
* [Combine selection with other Grid features](#integration-with-other-grid-features)
5520

56-
<TelerikGrid Data=@GridData
57-
SelectionMode="@selectionMode"
58-
Pageable="true">
59-
<GridColumns>
60-
<GridCheckboxColumn SelectAll="@( selectionMode == GridSelectionMode.Single ? false : true )" Title="Select" Width="70px" />
61-
<GridColumn Field=@nameof(Employee.Name) />
62-
<GridColumn Field=@nameof(Employee.Team) Title="Team" />
63-
</GridColumns>
64-
</TelerikGrid>
65-
66-
@code {
67-
public List<Employee> GridData { get; set; }
21+
## Enable Row or Cell Selection
6822

69-
GridSelectionMode selectionMode = GridSelectionMode.Single;
23+
You can configure the Grid either for row or cell selection:
7024

71-
protected override void OnInitialized()
72-
{
73-
GridData = new List<Employee>();
74-
for (int i = 0; i < 15; i++)
75-
{
76-
GridData.Add(new Employee()
77-
{
78-
EmployeeId = i,
79-
Name = "Employee " + i.ToString(),
80-
Team = "Team " + i % 3
81-
});
82-
}
83-
}
25+
* To enable row selection:
26+
* Set the [Grid `SelectionMode` parameter](#use-single-or-multiple-selection) or
27+
* Add a `<GridSelectionSettings>` tag to the `<GridSettings>` tag, and set the `SelectionType` parameter to `GridSelectionType.Row`.
28+
* Optionally, you can also select rows through the [checkbox column]({%slug components/grid/columns/checkbox%}).
29+
* To enable cell selection:
30+
* Add a `<GridSelectionSettings>` tag to the `<GridSettings>` tag, and set the `SelectionType` parameter to the `Cell` member of the `Telerik.Blazor.GridSelectionType` enum.
8431

85-
public class Employee
86-
{
87-
public int EmployeeId { get; set; }
88-
public string Name { get; set; }
89-
public string Team { get; set; }
90-
}
91-
}
92-
````
32+
See [Rows Selection Options]({%slug grid-selection-row%}#basics) and [Cells Selection Options]({%slug grid-selection-cell%}#basics) for more details.
9333

94-
### Example - Select rows with checkboxes only
34+
## Use Single or Multiple Selection
9535

96-
````CSHTML
97-
@* Require clicks on the checkboxes for row selection*@
36+
You can configure the selection behavior by setting the Grid `SelectionMode` parameter to a member of the `Telerik.Blazor.GridSelectionMode` enum. The Grid supports the following selection modes:
9837

99-
<TelerikGrid Data=@GridData Navigable="true"
100-
SelectionMode="GridSelectionMode.Multiple"
101-
Pageable="true"
102-
Height="400px">
103-
<GridColumns>
104-
<GridCheckboxColumn CheckBoxOnlySelection="true" />
105-
<GridColumn Field=@nameof(Employee.Name) />
106-
<GridColumn Field=@nameof(Employee.Team) Title="Team" />
107-
</GridColumns>
108-
</TelerikGrid>
38+
* `None` (default)—Disables row and cell selection.
39+
* `Single`—Allows the user to select only one cell or row at a time. If the user attempts to select multiple cells or rows sequentially, only the most recent selection will take effect.
40+
* `Multiple`—Allows the user to select multiple rows or cells at a time.
10941

110-
@code {
111-
public List<Employee> GridData { get; set; }
42+
## Access Selected Rows or Cells
11243

113-
protected override void OnInitialized()
114-
{
115-
GridData = new List<Employee>();
116-
for (int i = 0; i < 15; i++)
117-
{
118-
GridData.Add(new Employee()
119-
{
120-
EmployeeId = i,
121-
Name = "Employee " + i.ToString(),
122-
Team = "Team " + i % 3
123-
});
124-
}
125-
}
44+
The Grid exposes two parameters to get or set its selected rows and cells.
12645

127-
public class Employee
128-
{
129-
public int EmployeeId { get; set; }
130-
public string Name { get; set; }
131-
public string Team { get; set; }
132-
}
133-
}
134-
````
46+
* Use the `SelectedItems` parameter (`IEnumerable<T>`) to access the selected rows.
47+
* Use the `SelectedCells` parameter (`IEnumerable<GridSelectedCellDescriptor>`) to access the selected cells.
13548

49+
Both parameters support two-way binding. You can also use the parameters to pre-select rows or cells for your users.
13650

137-
## Notes
51+
See [Selected Rows]({%slug grid-selection-row%}#selected-rows) and [Selected Cells]({%slug grid-selection-cell%}#selected-cells) for more details.
13852

139-
### Editing Modes
53+
## Events
14054

141-
#### InCell Edit Mode
55+
You can respond to the user action of selecting a new item through the Grid events:
14256

143-
In the [Incell EditMode]({%slug components/grid/editing/incell%}) selection can be applied only via a [checkbox column]({%slug components/grid/columns/checkbox%}) (`<GridCheckboxColumn />`). This is required due to the overlapping action that triggers selection and InCell editing (clicking in the row) - if row click selection was enabled with InCell editing, each attempt to select a row would put a cell in edit mode; and each attempt to edit a cell would select a new row. Such user experience is confusing, and so selection will only work through the row selection checkbox.
57+
* Use the [`SelectedItemsChanged` event]({%slug grid-selection-row%}#selecteditemschanged) to respond to row selection.
58+
* Use the [`SelectedCellsChanged` event]({%slug grid-selection-cell%}#selectedcellschanged) to respond to cell selection.
14459

145-
To see how to select the row that is being edited in InCell edit mode without using a `<GridCheckboxColumn />` check out the [Row Selection in Edit with InCell EditMode]({%slug grid-kb-row-select-incell-edit%}) Knowledge Base article.
60+
## Integration with Other Grid Features
14661

147-
#### Inline and Popup Edit Modes
148-
149-
In [Inline EditMode]({%slug components/grid/editing/inline%}) and [Popup EditMode]({%slug components/grid/editing/popup%}) selection can be done by clicking on the desired row or by using a `<GridCheckboxColumn />`.
150-
151-
### Selection in Template
152-
153-
When using the [Grid column Template]({%slug grid-templates-column%}) and you want to stop the Selection from being triggered when the user clicks in it, you should add the `@onclick:stopPropagation` directive to the element.
154-
155-
>caption Prevent row selection from happening when the user clicks inside a template
156-
157-
````CSHTML
158-
<GridColumn Field=@nameof(Product.ProductId) Title="Id">
159-
<Template>
160-
<span @onclick:stopPropagation>
161-
<TelerikNumericTextBox Value="@((context as Product).ProductId)"></TelerikNumericTextBox>
162-
</span>
163-
</Template>
164-
</GridColumn>
165-
````
166-
167-
If you are using the [Row Template]({%slug components/grid/features/templates%}#row-template), the grid cannot render selection checkboxes for you, so you have to bind them yourself to a field in the model, and handle their selection changed event to populate the `SelectedItems` collection of the grid. You can find an example to get started in the following thread: [Grid Row Template with Selection - Unsure how to Bind to Selected Item](https://feedback.telerik.com/blazor/1463819-grid-row-template-with-selection-unsure-how-to-bind-to-selected-item)
168-
169-
### Asynchronous Operations
170-
171-
Asynchronous operations such as loading data on demand should be handled in the [`OnRowClick`]({%slug grid-events%}#onrowclick) or [`OnRowDoubleClick`]({%slug grid-events%}#onrowdoubleclick) events rather than in the [`SelectedItemsChanged`]({%slug grid-events%}#selecteditemschanged).
172-
173-
### SelectedItems Equals Comparison
174-
175-
The `SelectedItems` collection is compared against the Grid `Data` collection in order to determine which rows will be highlighted. The default behavior of the framework is to compare objects by their reference.
176-
177-
When the `SelectedItems` are obtained from a different data source to the Grid (e.g., from a separate service method and not from the view-model), the references may not match and so there will be no highlighted items. In such cases, you have to [override the `Equals` method of the underlying model class]({%slug grid-state%}#equals-comparison) so that it matches them, for example, by a unique identifier rather than by reference so that two objects can be equal regardless of their origin, but according to their contents. When you are overriding the `Equals` method, it is also recommended to override the [`GetHashCode`](https://docs.microsoft.com/en-us/dotnet/api/system.object.gethashcode) method as well.
178-
179-
### Handle Data Changes
180-
181-
When the grid `Data` collection changes, the `SelectedItems` collection has the following behavior:
182-
183-
* If the Grid does *not* use an `ObservableCollection` for its `Data` - The `SelectedItems` collection will be preserved. You need to clear or manipulate it when the data is changed according to your needs and business logic.
184-
185-
* If you update or delete an item, you must make the same update in the selected items through the grid [editing events]({%slug components/grid/editing/overview%}).
186-
187-
* When using an `ObservableCollection` for the grid `Data`- If an item is removed or the entire data is cleared using the collection's `.Clear()` method, it will automatically update the `SelectedItems` collection too (the removed Data items will be removed from the Selected Items collection).
188-
189-
* The other CRUD operations (Create and Update), you should use the grid [editing events]({%slug components/grid/editing/overview%}) to handle the situation according to your business logic and preferred behavior.
190-
* When the data changes and the selected items are cleared, the `SelectedItemsChanged` event will fire with the empty collection. If you are using two-way binding, the collection will be cleared.
191-
192-
### Selection in Grid with virtualized rows
193-
194-
When the Grid has [virtualized rows]({%slug components/grid/virtual-scrolling%}) and the `SelectionMode` is set to [`Multiple`]({%slug components/grid/selection/multiple%}) the selectable items will be the one in the current set of items (page). If you select an item and scroll down to some of the ones that are not rendered yet (virtualization kicks in) and you want to select that range with the `Shift` button, the selection will start from the position of the first item of the current set (page) to the last selected item.
195-
196-
### Row Drag and Drop
197-
198-
If the user drags selected rows, the current row selection will be cleared on row drop.
62+
The selection feature behavior may differ when the Grid configuration includes row or cell selection and other Grid features. In these situations, certain limitations might arise, or additional adjustments may be required.
19963

64+
See [Rows Selection and Other Grid Features]({%slug grid-selection-row%}#row-selection-and-other-grid-features) and [Cells Selection and Other Grid Features]({%slug grid-selection-cell%}#cell-selection-and-other-grid-features) for more details.
20065

20166
## See Also
20267

203-
* [Live Demo: Grid Selection](https://demos.telerik.com/blazor-ui/grid/selection)
204-
* [Single Selection]({%slug components/grid/selection/single%})
205-
* [Multiple Selection]({%slug components/grid/selection/multiple%})
68+
* [Live Demo: Grid Row Selection](https://demos.telerik.com/blazor-ui/grid/row-selection)
69+
* [Live Demo: Grid Cell Selection](https://demos.telerik.com/blazor-ui/grid/cell-selection)

‎components/grid/selection/rows.md‎

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
---
2+
title: Row Selection
3+
page_title: Grid - Rows Selection
4+
description: Learn how to select row in Blazor Grid component. Explore the selected rows. Discover row selection bevahior when combined with other Grid features. Try the practical sample code for row selection.
5+
slug: grid-selection-row
6+
tags: telerik,blazor,grid,selection,rows
7+
previous_url: /components/grid/selection/single,/components/grid/selection/multiple
8+
position: 3
9+
---
10+
11+
# Row Selection
12+
13+
The Grid component supports [single or multiple row selection]({%slug grid-selection-overview%}#use-single-or-multiple-selection). You can select a row with mouse click and through a checkbox column. You can access the collection of selected rows, use this collection and modify it. You can subscribe to selection events.
14+
15+
## Basics
16+
17+
By default, users can select rows by clicking anywhere in the row, except on command buttons.
18+
19+
To select a range of rows, hold the **Shift** key, while clicking on the first and last row of the range. To select or deselect multiple rows that don't belong to a range, hold the **Ctrl** key.
20+
21+
Check the [Grid Keyboard navigation demo](https://demos.telerik.com/blazor-ui/grid/keyboard-navigation) for detailed information about selecting rows with the keyboard.
22+
23+
You can also render a checkbox column that allows users to select and deselect rows. To use checkbox selection, add a [`GridCheckboxColumn`]({%slug components/grid/columns/checkbox%}) in the `GridColumns` collection of the Grid. The `GridCheckboxColumn` provides [additional configuration settings related to selection]({%slug components/grid/columns/checkbox%}#parameters).
24+
25+
>caption Grid multiple row selection
26+
27+
````CSHTML
28+
<TelerikGrid Data="@GridData"
29+
SelectionMode="@GridSelectionMode.Multiple"
30+
@bind-SelectedItems="@SelectedEmployees"
31+
Pageable="true">
32+
<GridColumns>
33+
<GridCheckboxColumn SelectAll="true" CheckBoxOnlySelection="false" />
34+
<GridColumn Field="@nameof(Employee.Name)" />
35+
<GridColumn Field="@nameof(Employee.Team)" />
36+
</GridColumns>
37+
</TelerikGrid>
38+
39+
<h3>Selected Employees:</h3>
40+
41+
<ul>
42+
@foreach (Employee employee in SelectedEmployees)
43+
{
44+
<li>@employee.Name</li>
45+
}
46+
</ul>
47+
48+
@code {
49+
private List<Employee> GridData { get; set; } = new();
50+
51+
private IEnumerable<Employee> SelectedEmployees { get; set; } = Enumerable.Empty<Employee>();
52+
53+
protected override void OnInitialized()
54+
{
55+
for (int i = 1; i <= 15; i++)
56+
{
57+
GridData.Add(new Employee()
58+
{
59+
EmployeeId = i,
60+
Name = $"Employee {i}",
61+
Team = $"Team {i % 3 + 1}"
62+
});
63+
}
64+
65+
SelectedEmployees = new List<Employee>() { GridData.ElementAt(2) };
66+
}
67+
68+
public class Employee
69+
{
70+
public int EmployeeId { get; set; }
71+
public string Name { get; set; } = string.Empty;
72+
public string Team { get; set; } = string.Empty;
73+
}
74+
}
75+
````
76+
77+
## SelectedItemsChanged Event
78+
79+
You can respond to user selection actions through the `SelectedItemsChanged` event. The event handler receives a collection of the Grid data model. The collection may have multiple, single, or no items in it, depending on the `SelectionMode` and the last user selection.
80+
81+
>caption Using the Grid SelectedItemsChanged event
82+
83+
````CSHTML
84+
<TelerikGrid Data="@GridData"
85+
SelectionMode="@GridSelectionMode.Multiple"
86+
SelectedItems="@SelectedEmployees"
87+
SelectedItemsChanged="@( (IEnumerable<Employee> newSelected) => OnRowSelect(newSelected) )"
88+
Pageable="true">
89+
<GridColumns>
90+
<GridCheckboxColumn SelectAll="true" CheckBoxOnlySelection="false" />
91+
<GridColumn Field="@nameof(Employee.Name)" />
92+
<GridColumn Field="@nameof(Employee.Team)" />
93+
</GridColumns>
94+
</TelerikGrid>
95+
96+
<p><code>SelectedItemsChanged</code> fired at: @SelectedItemsChangedLog</p>
97+
98+
<h3>Selected Employees:</h3>
99+
100+
<ul>
101+
@foreach (Employee employee in SelectedEmployees)
102+
{
103+
<li>@employee.Name</li>
104+
}
105+
</ul>
106+
107+
@code {
108+
private List<Employee> GridData { get; set; } = new();
109+
110+
private IEnumerable<Employee> SelectedEmployees { get; set; } = Enumerable.Empty<Employee>();
111+
112+
private string SelectedItemsChangedLog { get; set; } = string.Empty;
113+
114+
protected void OnRowSelect(IEnumerable<Employee> employees)
115+
{
116+
// Update the SelectedItems collection manually.
117+
// When using two-way binding, this happens automatically.
118+
SelectedEmployees = employees;
119+
120+
SelectedItemsChangedLog = DateTime.Now.ToLongTimeString();
121+
}
122+
123+
protected override void OnInitialized()
124+
{
125+
for (int i = 1; i <= 15; i++)
126+
{
127+
GridData.Add(new Employee()
128+
{
129+
EmployeeId = i,
130+
Name = $"Employee {i}",
131+
Team = $"Team {i % 3 + 1}"
132+
});
133+
}
134+
135+
SelectedEmployees = new List<Employee>() { GridData.ElementAt(2) };
136+
}
137+
138+
public class Employee
139+
{
140+
public int EmployeeId { get; set; }
141+
public string Name { get; set; } = string.Empty;
142+
public string Team { get; set; } = string.Empty;
143+
}
144+
}
145+
````
146+
147+
### SelectedItemsChanged and Asynchronous Operations
148+
149+
The `SelectedItemsChanged` event handler cannot be awaited. To execute asynchronous operations when the user selects rows, use the [`OnRowClick`]({%slug grid-events%}#onrowclick) or [`OnRowDoubleClick`]({%slug grid-events%}#onrowdoubleclick) event instead.
150+
151+
## Selection When Data Changes
152+
153+
When the Grid `Data` collection changes, the `SelectedItems` collection has the following behavior:
154+
155+
* When the user updates a selected item and the item instance is replaced, you have to also replace the selected item object in the `SelectedItems` collection. Do that in the [Grid `OnUpdate` event]({%slug components/grid/editing/overview%}#events).
156+
* When the user deletes a selected item, the Grid automatically deletes it from the `SelectedItems` collection and the [`SelectedItemsChanged` event](#selecteditemschanged) fires.
157+
* To select a new item in the Grid you can use the [`OnCreate` event]({%slug components/grid/editing/overview%}#events) to update the `SelectedItems` collection.
158+
159+
## Equals Comparison
160+
161+
The items in `SelectedItems` are compared against the items in the Grid data in order to determine which rows will be highlighted. The default framework behavior is to compare objects by reference. The data item references may not match when:
162+
163+
* The Grid is databound through its `OnRead` event and each data request returns different data item instances.
164+
* The `SelectedItems` are obtained from a different data source than the all Grid items, for example, from a separate service.
165+
166+
In such cases, the selected rows may not appear as expected. You have to [override the `Equals` method of the Grid model class]({%slug grid-state%}#equals-comparison) so that the items are compared by a unique identifier rather than by reference. When you override `Equals`, it is also recommended to override the [`GetHashCode`](https://docs.microsoft.com/en-us/dotnet/api/system.object.gethashcode) method.
167+
168+
## Row Selection and Other Grid Features
169+
170+
The selection behavior may vary when other Grid features are enabled, such as editing, virtualization, paging, column and row templates, row drag and drop. In such cases you need to consider certain limitations or adjust the application code.
171+
172+
### Selection and Editing Modes
173+
174+
When users edit rows, the row selection has the following behavior:
175+
176+
* In [`Incell` edit mode]({%slug components/grid/editing/incell%}) the row selection can work only through a [checkbox column]({%slug components/grid/columns/checkbox%}). This is required due to the overlapping pointer events that trigger selection and editing. To see how to select the row that is being edited in `InCell` edit mode without using a `<GridCheckboxColumn />` check out the [Row Selection in Edit with InCell EditMode]({%slug grid-kb-row-select-incell-edit%}) KB article.
177+
* [`Inline` edit mode]({%slug components/grid/editing/inline%}) and [`Popup` edit mode]({%slug components/grid/editing/popup%}) integrate with row selection without limitations.
178+
179+
### Selection and Virtual Scrolling
180+
181+
When the Grid has [virtual scrolling]({%slug components/grid/virtual-scrolling%}), the component is able to select a range of rows with **Shift** only if all rows in that range are currently rendered. Consider the following scenario:
182+
183+
1. Select a row.
184+
1. Scroll down, so that virtualization kicks in and the rendered rows are no longer the same.
185+
1. Select another row with **Shift**.
186+
187+
In this case, the range selection will start from the first row that is currently rendered.
188+
189+
### Selection and Paging
190+
191+
The `SelectedItems` collection persists across paging.
192+
193+
The [**Select All** checkbox in the Grid checkbox column]({%slug components/grid/columns/checkbox%}#parameters) cannot select items on other pages when using the Grid `OnRead` event.
194+
195+
### Selection and Templates
196+
197+
When using [Grid templates]({%slug components/grid/features/templates%}) with row selection:
198+
199+
* If you are using a [Grid column template]({%slug grid-templates-column%}) and you have a clickable element in the template, you can check the knowledge base article on [how to prevent row selection when the user clicks another component in the Grid column template]({%slug grid-kb-row-selection-in-column-template%}).
200+
* If you are using a [row template]({%slug components/grid/features/templates%}#row-template) the Grid cannot render a built-in [checkbox column]({%slug components/grid/columns/checkbox%}). You have to render checkboxes manually and handle their changed event to populate the `SelectedItems` collection of the Grid. You can find an example to get started in the following thread: [Grid Row Template with Selection - Unsure how to Bind to Selected Item](https://feedback.telerik.com/blazor/1463819-grid-row-template-with-selection-unsure-how-to-bind-to-selected-item).
201+
202+
### Selection and Row Drag and Drop
203+
204+
The Grid clears the `SelectedItems` collection when the user drags and drops selected rows.
205+
206+
## See Also
207+
208+
* [Live Demo: Grid Row Selection](https://demos.telerik.com/blazor-ui/grid/row-selection)

‎components/grid/selection/single.md‎

Lines changed: 0 additions & 249 deletions
This file was deleted.

‎components/grid/state.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The Grid state is a generic [class `GridState<TItem>`](/blazor-ui/api/Telerik.Bl
4040
| `OriginalEditItem` | `TItem`* | The original copy of the data item that is currently in edit mode. This `GridState` property holds the unmodified data item values. |
4141
| `Page` | `int?` | The current [page index]({%slug components/grid/features/paging%}). Some user actions reset the page index to 1, such as filtering or changing the page size. |
4242
| `SearchFilter` | `IFilterDescriptor` | The `CompositeFilterDescriptor` that holds the filter descriptors for the [`GridSearchBox`]({%slug grid-searchbox%}). |
43-
| `SelectedItems` | `ICollection<TItem>` | The currently [selected data item(s)]({%slug components/grid/selection/overview%}). |
43+
| `SelectedItems` | `ICollection<TItem>` | The currently [selected data item(s)]({%slug grid-selection-overview%}). |
4444
| `Skip` | `int?` | The number of scrolled data items when using [virtual row scrolling]({%slug components/grid/virtual-scrolling%}). In other words, this is the number of rows above the currently visible ones. |
4545
| `SortDescriptors` | `ICollection<SortDescriptor>` | The currently applied [sorts]({%slug components/grid/features/sorting%}). |
4646
| `TableWidth` | `string` | The sum of all visible column widths. This property changes together with `ColumnStates`. The `OnStateChanged` event does not fire separately for it. |

‎components/grid/virtual-scrolling.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ These are the known limitations of the virtual scrolling feature:
330330
## See Also
331331

332332
* [Live Demo: Grid Virtual Scrolling](https://demos.telerik.com/blazor-ui/grid/virtual-scrolling)
333-
* [Selection in Grid with Virtualized Rows]({%slug components/grid/selection/overview%}#selection-in-grid-with-virtualized-rows)
333+
* [Selection in Grid with Virtualized Rows]({%slug grid-selection-overview%}#selection-in-grid-with-virtualized-rows)
334334
* [Knowledge Base Article: Virtual Scroll Does Not Show All Items]({%slug grid-kb-virtualization-many-records%})
335335
* [Knowledge Base Article: Virtual Scrolling Does Not Work]({%slug grid-kb-virtual-scrolling-troubleshooting%})
336336
* [Knowledge Base Article: Setting Too Large Skip]({%slug grid-kb-large-skip-virtualization%})

‎knowledge-base/grid-allow-prevent-row-selection.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ The key points in the required implementation are:
106106

107107
## See Also
108108

109-
* [Grid Selection]({%slug components/grid/selection/overview%})
109+
* [Grid Selection]({%slug grid-selection-overview%})

‎knowledge-base/grid-edit-selected-item.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ You can use the regular [TelerikButton]({%slug components/button/overview%}) and
3333

3434
1. Create a new instance of the class you bound the Grid to in order to contain the information for the selected item.
3535

36-
1. Use one-way data binding for the [SelectedItems]({%slug components/grid/selection/single%}) parameter and in the handler for the [SelectedItemsChanged]({%slug grid-events%}#selecteditemschanged) populate the instance of the class created in the previous point.
36+
1. Use one-way data binding for the [SelectedItems]({%slug grid-selection-row%}#selected-rows) parameter and in the handler for the [SelectedItemsChanged]({%slug grid-selection-row%}#selecteditemschanged) populate the instance of the class created in the previous point.
3737

3838
1. Enable the `Edit` and `Delete` buttons when the selected item is not `null` by using the `Enabled` parameter for the `TelerikButton`.
3939

‎knowledge-base/grid-export-selected-rows.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ How to export custom Grid data (for example the Grid selection) to CSV?
3333

3434
## Solution
3535

36-
1. Configure [Grid selection]({%slug components/grid/selection/overview%}) via the `SelectionMode` and `SelectedItems` parameters.
36+
1. Configure [Grid selection]({%slug grid-selection-overview%}) via the `SelectionMode` and `SelectedItems` parameters.
3737
1. Configure [Grid Excel export]({%slug grid-export-excel%}) or [Grid CSV export]({%slug grid-export-csv%}) via command buttons, for example in the [`<GridToolBarTemplate>`]({%slug components/grid/features/toolbar%}).
3838
1. Subscribe to the [`OnBeforeExport` event]({%slug grid-export-events%}) in `<GridExcelExport>` or `<GridCsvExport>`.
3939
1. In the `OnBeforeExport` handler, set the `Data` property of the event argument object to the Grid `SelectedItems` collection.
@@ -117,5 +117,5 @@ How to export custom Grid data (for example the Grid selection) to CSV?
117117
* [Grid Excel Export]({%slug grid-export-excel%})
118118
* [Grid CSV Export]({%slug grid-export-csv%})
119119
* [Grid Export Events]({%slug grid-export-events%})
120-
* [Grid Selection]({%slug components/grid/selection/overview%})
120+
* [Grid Selection]({%slug grid-selection-overview%})
121121
* [Grid ToolBar]({%slug components/grid/features/toolbar%})

‎knowledge-base/grid-filter-by-selected-items.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ How can I achieve the following with the Blazor Grid:
3232

3333
To simulate filtering by the selected items:
3434

35-
1. Get the [`SelectedItems`]({%slug components/grid/selection/multiple%}#selected-items) data and assign it as Grid data. Thus, the Grid will show only the selected items. This will allow the user to perform the desired data operations only to the selected items.
35+
1. Get the [`SelectedItems`]({%slug grid-selection-row%}#selected-rows) data and assign it as Grid data. Thus, the Grid will show only the selected items. This will allow the user to perform the desired data operations only to the selected items.
3636

3737
1. To clear this "filter" and show all items (not only the selected ones), assign the actual data source to the Grid.
3838

39-
1. Consider and choose the desired UI for triggering that custom filtering, for example, a filter button or menu. Use the needed template to declare the custom filter UI in the Grid. Useful options can be the [Toolbar]({%slug components/grid/features/toolbar%}) or the [Checkbox Column Header]({%slug components/grid/columns/checkbox%}#header-template)(in case you are using [CheckBox selection]({%slug components/grid/selection/multiple%}#checkbox-selection)).
39+
1. Consider and choose the desired UI for triggering that custom filtering, for example, a filter button or menu. Use the needed template to declare the custom filter UI in the Grid. Useful options can be the [Toolbar]({%slug components/grid/features/toolbar%}) or the [Checkbox Column Header]({%slug components/grid/columns/checkbox%}#header-template)(in case you are using [CheckBox selection]({%slug grid-selection-row%}#basics)).
4040

41-
> [Override the `Equals` method]({%slug components/grid/selection/overview%}#selecteditems-equals-comparison) so that the selection is preserved during filtering.
41+
> [Override the `Equals` method]({%slug grid-selection-overview%}#selecteditems-equals-comparison) so that the selection is preserved during filtering.
4242
4343
The data assignment will vary depending on the [data binding type you are using for the Grid]({%slug grid-data-binding%}#basics). See examples below:
4444
* [Data binding through the Data parameter](#data-binding-through-the-`data`-parameter)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: How to Select a Row in the Grid when Using Grid Column Template
3+
description: Learn how to manage row selection in the Telerik Blazor Grid when using Grid Column Template.
4+
type: how-to
5+
page_title: Select a Row in the Grid when Using Grid Column Template
6+
slug: grid-kb-row-selection-in-column-template
7+
tags: grid, selection, templates
8+
ticketid:
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>Grid for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
This KB article answers the following question:
26+
27+
* How to use row selection but stop the selection from triggering when the user clicks on another component in the Grid column template?
28+
29+
## Solution
30+
31+
When you use the [Grid Column Template]({%slug grid-templates-column%}) and want to stop the selection from triggering when the user clicks on the element rendered by the template, add the `@onclick:stopPropagation` directive to the element.
32+
33+
>caption Prevent row selection when the user clicks inside a template
34+
35+
````CSHTML
36+
<select @bind=@SelectionMode>
37+
<option value=@GridSelectionMode.Single>Single</option>
38+
<option value=@GridSelectionMode.Multiple>Multiple</option>
39+
</select>
40+
41+
<TelerikGrid Data=@GridData
42+
SelectionMode="@SelectionMode"
43+
Pageable="true">
44+
<GridColumns>
45+
<GridCheckboxColumn SelectAll="@( SelectionMode == GridSelectionMode.Single ? false : true )" Title="Select" Width="70px" />
46+
<GridColumn Field=@nameof(Employee.Name) />
47+
<GridColumn Field=@nameof(Employee.Team) Title="Team" />
48+
<GridColumn Field=@nameof(Employee.TeamMembersCount) Title="Team Members Count">
49+
<Template>
50+
@* Remove the @onclick:stopPropagation and see how each click in the NumericTextBox triggers the row selection *@
51+
<span @onclick:stopPropagation>
52+
<TelerikNumericTextBox Value="@((context as Employee).TeamMembersCount)"></TelerikNumericTextBox>
53+
</span>
54+
</Template>
55+
</GridColumn>
56+
</GridColumns>
57+
</TelerikGrid>
58+
59+
@code {
60+
private List<Employee> GridData { get; set; }
61+
62+
private GridSelectionMode SelectionMode = GridSelectionMode.Single;
63+
64+
protected override void OnInitialized()
65+
{
66+
GridData = new List<Employee>();
67+
for (int i = 0; i < 15; i++)
68+
{
69+
GridData.Add(new Employee()
70+
{
71+
EmployeeId = i,
72+
Name = "Employee " + i.ToString(),
73+
Team = "Team " + i % 3
74+
});
75+
}
76+
}
77+
78+
public class Employee
79+
{
80+
public int EmployeeId { get; set; }
81+
public string Name { get; set; }
82+
public string Team { get; set; }
83+
public int TeamMembersCount { get; set; }
84+
}
85+
}
86+
````
87+
88+
## See Also
89+
90+
* [Grid Selection]({%slug grid-selection-overview%})

‎knowledge-base/grid-select-or-deselect-item-on-row-click.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ How can I select and deselect multiple rows by clicking on a row in a Grid with
2727

2828
## Solution
2929

30-
When Grid selection is enabled, the built-in option for deselecting a row or selecting multiple rows is `Ctrl` + Click (`Cmd` + Click on Macs) - see the [Grid Selection article]({%slug components/grid/selection/overview%}) for more details. To deselect a row or select multiple rows by row clicking and without holding the `Ctrl` key, use the following approach:
30+
When Grid selection is enabled, the built-in option for deselecting a row or selecting multiple rows is `Ctrl` + Click (`Cmd` + Click on Macs) - see the [Grid Selection article]({%slug grid-selection-overview%}) for more details. To deselect a row or select multiple rows by row clicking and without holding the `Ctrl` key, use the following approach:
3131

3232
* Cancel the built-in selection. You can achieve that by handling the `SelectedItemsChanged` event and not executing any logic in it.
3333

0 commit comments

Comments
 (0)
Please sign in to comment.