You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* How to [select rows]({%slug grid-selection-row%}) in the Grid when using a [Row Template]({%slug grid-templates-row%})?
30
-
* How to add a [Checkbox column]({%slug components/grid/columns/checkbox%}) in the Grid when using a Row Template? I want to be able to select the row through its checkbox, but also to have the functionality to [select all rows]({%slug components/grid/columns/checkbox%}#parameters) from the header of the Checkbox column.
31
-
* Do the built-in keyboard options to select a range of rows by clicking the **Shift** or **Ctrl** key work when using a Row Template? How to check the checkbox of the row when I select a row by clicking the row?
30
+
* How to add a [checkbox column]({%slug components/grid/columns/checkbox%}) in the Grid when using a Row Template? I want to be able to select the row through its checkbox, but also to have the functionality to [select all rows]({%slug components/grid/columns/checkbox%}#parameters) from the header of the checkbox column.
31
+
* Do the built-in keyboard options to select a range of rows by clicking the `Shift` or `Ctrl` key work when using a Row Template? How to check the checkbox of the row when I select a row by clicking the row?
32
32
* How to add a [command column]({%slug components/grid/columns/command%}) in the Grid when using a Row Template?
33
-
* When using a Row Template how to prevent the selection of Grid rows when clicking on command buttons?
33
+
* When using a Row Template, how to prevent the selection of Grid rows when clicking on command buttons?
34
34
* How to implement Grid column [resizing]({%slug components/grid/columns/resize%}), [auto-fitting]({%slug components/grid/columns/resize%}#autofit-columns), [visibility]({%slug grid-columns-visible%}), [locking]({%slug grid-columns-frozen%}), and [reordering]({%slug components/grid/columns/reorder%}) when using a Row Template?
35
35
36
36
## Solution
37
37
38
-
By default, using the Row Template takes the majority of built-in functionalities away from the Grid because the Grid no longer controls its own rendering. This gives you the control to add your own implementation for them. The example below showcases a possible implementation of some of the functionalities, such as row selection by clicking on a row and through a Checkbox column, column resizing and visibility, editing through command buttons, sorting, filtering.
38
+
By default, using the Row Template disables most built-in functionalities of the Grid because the Grid no longer controls its own rendering. This lets you add custom implementations for these features. The [example below](#example) shows one way to implement functionalities such as row selection (both by clicking on a row and through a checkbox column), column resizing and visibility, editing through command buttons, sorting, and filtering.
39
39
40
40
### Selection
41
41
42
-
* In the [`<GridColumns>` collection]({%slug components/grid/columns/bound%}#show-data-in-a-grid) add the [`<GridCheckboxColumn>`]({%slug components/grid/columns/checkbox%}) and use the [`HeaderTemplate`]({%slug components/grid/columns/checkbox%}#header-template) to add a custom [CheckBox component]({%slug checkbox-overview%}). This CheckBox component handles the [select all rows]({%slug components/grid/columns/checkbox%}#parameters) functionallity.
43
-
* In the `<RowTemplate>`, add a `<td>` element with a custom CheckBox component. Add a Boolean property to the Grid model to indicate selection so you can use it for the state of this CheckBox.
44
-
* Handle the Grid's [`SelectedItemsChanged` event]({%slug grid-selection-row%}#selecteditemschanged-event) and the CheckBox's [`OnChange` event]({%slug checkbox-events%}#onchange) to manage the [`SelectedItems` collection]({%slug grid-selection-overview%}#access-selected-rows-or-cells). The `OnChange` event fires after the `SelectedItemsChanged` event. In this case, you need to create a separate collection of selected items to persist the selected items when multiselecting through the CheckBox.
42
+
To implement custom selection functionality:
43
+
44
+
* In the [`<GridColumns>` collection]({%slug components/grid/columns/bound%}#show-data-in-a-grid) add the [`<GridCheckboxColumn>`]({%slug components/grid/columns/checkbox%}) and use the [`HeaderTemplate`]({%slug components/grid/columns/checkbox%}#header-template) to add a [CheckBox component]({%slug checkbox-overview%}). This CheckBox component handles the [select all rows]({%slug components/grid/columns/checkbox%}#parameters) functionallity.
45
+
* In the Row Template, add a `<td>` element with a CheckBox component. Add a Boolean property to the Grid model to indicate selection so you can use it for the state of this CheckBox.
46
+
* Handle the Grid's [`SelectedItemsChanged` event]({%slug grid-selection-row%}#selecteditemschanged-event) and the CheckBox's [`OnChange` event]({%slug checkbox-events%}#onchange) to manage the [`SelectedItems` collection]({%slug grid-selection-overview%}#access-selected-rows-or-cells). The `OnChange` event fires after the `SelectedItemsChanged` event. In this case, you need to create a separate collection of selected items to persist the selected items when multiselecting through the checkbox column.
45
47
46
48
### Editing, Sorting, Filtering
47
49
48
-
The built-in editing, sorting, and filtering will work if the RowTemplate structure is similar to an actual table and only for the first Grid data model property included in the `<td>` element, if any.
50
+
The built-in editing, sorting, and filtering will work if the Row Template structure is similar to an actual table and only for the first Grid data model property included in the `<td>` element, if any.
49
51
50
52
### Command Column
51
53
54
+
To implement a custom command column:
55
+
52
56
* In the `<GridColumns>` collection add the [`<GridCommandColumn>`]({%slug components/grid/columns/command%}) and use the [built-in `Save` and `Cancel` commands]({%slug components/grid/columns/command%}#built-in-commands).
53
-
* In the `<RowTemplate>`add a `<td>` element with custom[Button component]({%slug components/button/overview%}) and handle the Grid items editing and deleting programmatically. You can refer to the knowledge base article on how to [enter and exit Grid edit mode programmatically]({%slug grid-kb-add-edit-state%}).
57
+
* In the Row Template add a `<td>` element with a[Button component]({%slug components/button/overview%}) and handle the Grid items editing and deleting programmatically. Refer to the knowledge base article on how to [enter and exit Grid edit mode programmatically]({%slug grid-kb-add-edit-state%}).
54
58
* Set the <ahref="https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation"target="_blank">`stopPropagation` method</a> of the <ahref="https://www.w3schools.com/jsref/event_onclick.asp"target="_blank">`onclick` event</a> to the `<td>` element to prevent row selection when clicking a command button.
* Column resizing and auto-fitting will work if the Row Template structure resembles an actual table row, with a corresponding number of cells matching the Grid columns.
59
-
*The column visibility depends if you include a `<td>` element for the column in the Row Template.
60
-
* To implement column locking, add the `k-grid-content-sticky` class to the `<td>` element of the columns that you want locked, and calculate and set the correct `left` and `right` CSS properties, as the content inside the template can be any valid HTML.
63
+
*Column visibility depends on including a `<td>` element for the column in the Row Template.
64
+
* To implement column locking, add the `k-grid-content-sticky` class to the `<td>` element of the columns that you want locked, and calculate and set the correct `left` and `right` CSS properties, as the content inside the Row Template can be any valid HTML.
61
65
* For column reordering, manage the `left` and `right` CSS properties on the `<td>` elements within the Row Template.
62
66
63
67
## Example
@@ -69,7 +73,6 @@ The built-in editing, sorting, and filtering will work if the RowTemplate struct
69
73
Data=@GridData
70
74
Pageable="true"
71
75
PageSize="15"
72
-
Page="1"
73
76
Sortable="true"
74
77
Resizable="true"
75
78
FilterMode="@GridFilterMode.FilterMenu"
@@ -134,6 +137,7 @@ The built-in editing, sorting, and filtering will work if the RowTemplate struct
134
137
private bool SelectAll { get; set; }
135
138
136
139
#region Selection
140
+
137
141
private void SelectAllHandler(bool newValue)
138
142
{
139
143
SelectAll = newValue;
@@ -144,7 +148,7 @@ The built-in editing, sorting, and filtering will work if the RowTemplate struct
144
148
}
145
149
146
150
// If SelectAll is true, assign all items to SelectedItems,
147
-
// else set it to an empty list
151
+
// else set it to an empty list.
148
152
SelectedItems = SelectAll ? new List<ArticleDto>(GridData) : new List<ArticleDto>();
149
153
TempSelectedItemsCollection = SelectAll ? new List<ArticleDto>(GridData) : new List<ArticleDto>();
150
154
}
@@ -157,7 +161,7 @@ The built-in editing, sorting, and filtering will work if the RowTemplate struct
157
161
}
158
162
159
163
// Use temporary collection to be able to persist the
160
-
// selected items when multiselecting with checkboxes
164
+
// selected items when multiselecting with checkboxes.
0 commit comments