Skip to content

Commit 4cbf777

Browse files
authored
docs(grid): Improve CheckBoxColumn Title info and example (#1746)
1 parent 6aa6883 commit 4cbf777

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

components/grid/columns/checkbox.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The Grid checkbox column has the following exclusive parameters. For other avail
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. |
2828
| `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). |
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. |
30+
| `Title` | `string` | The text in the checkbox column's header. The title renders only when `SelectAll` is `false`. |
3031

3132
>note If the Grid is bound to `IQueriable`, a header checkbox with an `All` option will execute the query over all the data. This may be a performance hit.
3233
@@ -36,22 +37,28 @@ The `HeaderTemplate` of the Grid checkbox column enables developers to customize
3637

3738
On a side note, it is possible to [center the checkboxes in the `GridCheckboxColumn`]({%slug grid-kb-center-checkbox-column%}) without using a template.
3839

40+
The example below doesn't take into account sorting, filtering and paging. If the Grid has any data operations enabled, replace `GridData` in the custom logic below with the [data collection, which the Grid is currently showing]({%slug grid-kb-get-filtered-data%}).
41+
3942
>caption Grid Checkbox Column Header Template
4043
4144
````CSHTML
42-
<TelerikGrid @ref="@GridRef"
43-
Data="@GridData"
45+
@*If the Grid has data operations enabled, see
46+
https://docs.telerik.com/blazor-ui/knowledge-base/grid-get-filtered-data
47+
on how to get the data collection, which the Grid is currently showing.
48+
Use this collection instead of GridData in the custom logic.*@
49+
50+
<TelerikGrid Data="@GridData"
4451
SelectionMode="GridSelectionMode.Multiple"
4552
@bind-SelectedItems="SelectedItems">
4653
<GridColumns>
47-
<GridCheckboxColumn Width="140px" HeaderClass="header-select-all">
54+
<GridCheckboxColumn Width="160px" HeaderClass="header-select-all">
4855
<HeaderTemplate>
4956
@{
5057
<TelerikCheckBox @bind-Value="@SelectAllCheckBoxValue"
5158
Enabled="@SelectAllEnabled"
5259
TabIndex="-1"
5360
Indeterminate="@(SelectAllCheckBoxValue == null)" />
54-
61+
<span>&nbsp;</span>
5562
<TelerikButton OnClick="@ToggleSelectAll">
5663
@(SelectAllCheckBoxValue.HasValue && SelectAllCheckBoxValue.Value ? "Deselect All" : "Select All")
5764
</TelerikButton>
@@ -63,7 +70,7 @@ On a side note, it is possible to [center the checkboxes in the `GridCheckboxCol
6370
</TelerikGrid>
6471
6572
<style>
66-
.k-grid .header-select-all .k-checkbox {
73+
.k-grid .header-select-all .k-checkbox-wrap {
6774
vertical-align: middle;
6875
}
6976
@@ -74,12 +81,13 @@ On a side note, it is possible to [center the checkboxes in the `GridCheckboxCol
7481
</style>
7582
7683
@code {
77-
List<Product> GridData { get; set; }
78-
TelerikGrid<Product> GridRef { get; set; }
79-
IEnumerable<Product> SelectedItems { get; set; } = Enumerable.Empty<Product>();
80-
bool SelectAllEnabled { get; set; }
84+
private List<Product> GridData { get; set; } = new List<Product>();
85+
86+
private IEnumerable<Product> SelectedItems { get; set; } = Enumerable.Empty<Product>();
87+
88+
private bool SelectAllEnabled { get; set; }
8189
82-
void ToggleSelectAll()
90+
private void ToggleSelectAll()
8391
{
8492
if (SelectAllCheckBoxValue.HasValue && SelectAllCheckBoxValue.Value)
8593
{
@@ -91,7 +99,7 @@ On a side note, it is possible to [center the checkboxes in the `GridCheckboxCol
9199
}
92100
}
93101
94-
bool? SelectAllCheckBoxValue
102+
private bool? SelectAllCheckBoxValue
95103
{
96104
get
97105
{
@@ -111,7 +119,7 @@ On a side note, it is possible to [center the checkboxes in the `GridCheckboxCol
111119
{
112120
if (value.HasValue && value.Value == true)
113121
{
114-
SelectedItems = GridRef.Data;
122+
SelectedItems = GridData;
115123
}
116124
else
117125
{
@@ -120,19 +128,19 @@ On a side note, it is possible to [center the checkboxes in the `GridCheckboxCol
120128
}
121129
}
122130
123-
bool IsAnyDataSelected()
131+
private bool IsAnyDataSelected()
124132
{
125-
return GridRef.SelectedItems.Count() > 0 && GridRef.SelectedItems.Count() < GridRef.Data.Count();
133+
return SelectedItems.Count() > 0 && SelectedItems.Count() < GridData.Count();
126134
}
127135
128-
bool IsAllDataSelected()
136+
private bool IsAllDataSelected()
129137
{
130-
return GridRef.SelectedItems.Count() == GridRef.Data.Count();
138+
return SelectedItems.Count() == GridData.Count();
131139
}
132140
133-
bool GridHasData()
141+
private bool GridHasData()
134142
{
135-
return GridRef.Data.Count() > 0;
143+
return GridData.Count() > 0;
136144
}
137145
138146
protected override void OnInitialized()

0 commit comments

Comments
 (0)