Skip to content

Commit 2a6a8cc

Browse files
committed
docs(Grid, TreeList): Improve TableWidth documentation in the State articles (#3020)
1 parent edc604b commit 2a6a8cc

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

_contentTemplates/grid/state.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,14 +716,17 @@
716716
<TelerikGrid @ref="@GridRef"
717717
Data="@GridData"
718718
Pageable="true"
719-
Reorderable="true">
719+
Reorderable="true"
720+
Resizable="true">
720721
<GridToolBarTemplate>
721722
<TelerikButton ThemeColor="@ThemeConstants.Button.ThemeColor.Success"
722723
OnClick="@ReorderPriceAndQuantity">Reorder Price and Quantity</TelerikButton>
723-
<TelerikButton ThemeColor="@ThemeConstants.Button.ThemeColor.Primary"
724+
<TelerikButton ThemeColor="@ThemeConstants.Button.ThemeColor.Success"
724725
OnClick="@MakeIdColumnLast">Make Id Column Last</TelerikButton>
726+
<TelerikButton ThemeColor="@ThemeConstants.Button.ThemeColor.Success"
727+
OnClick="@ResizeColumns">Resize Columns</TelerikButton>
725728
<span class="k-separator"></span>
726-
<TelerikButton OnClick="@ResetColumnOrder">Reset Column Order</TelerikButton>
729+
<TelerikButton OnClick="@ResetColumns">Reset Column Configuration</TelerikButton>
727730
</GridToolBarTemplate>
728731
<GridColumns>
729732
<GridColumn Field="@(nameof(Product.Id))" Width="80px" />
@@ -784,13 +787,32 @@
784787
}
785788
}
786789

787-
private async Task ResetColumnOrder()
790+
private async Task ResizeColumns()
791+
{
792+
if (GridRef != null)
793+
{
794+
var gridState = GridRef.GetState();
795+
int newColumnWidth = 160;
796+
797+
foreach (GridColumnState columnState in gridState.ColumnStates)
798+
{
799+
columnState.Width = $"{newColumnWidth}px";
800+
}
801+
802+
gridState.TableWidth = $"{newColumnWidth * gridState.ColumnStates.Count}px";
803+
804+
await GridRef.SetStateAsync(gridState);
805+
}
806+
}
807+
808+
private async Task ResetColumns()
788809
{
789810
if (GridRef != null)
790811
{
791812
var gridState = GridRef.GetState();
792813

793814
gridState.ColumnStates = new List<GridColumnState>();
815+
gridState.TableWidth = null;
794816

795817
await GridRef.SetStateAsync(gridState);
796818
}

components/grid/state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The Grid state is a generic [class `GridState<TItem>`](slug:Telerik.Blazor.Compo
4343
| `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). |
46-
| `TableWidth` | `string` | The sum of all visible column widths. This property changes together with `ColumnStates`. The `OnStateChanged` event does not fire separately for it. |
46+
| `TableWidth` | `string` | The sum of all visible column widths. The initial value is always `null` regardless of the column configuration. The `TableWidth` value changes during column resizing together with `ColumnStates` and the`OnStateChanged` event does not fire separately for it. When you resize a column programmatically, and all other columns already have widths, you must update the `TableWidth` too, otherwise the other columns will resize unexpectedly. |
4747

4848
\* `TItem` is the Grid model type.
4949

components/treelist/state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The TreeList state is a generic [class `TreeListState<TItem>`](slug:Telerik.Blaz
4242
| `SelectedItems` | `ICollection<TItem>` | The currently [selected data item(s)](slug:treelist-selection-overview). |
4343
| `Skip` | `int?` | The number of scrolled data items when using [virtual row scrolling](slug:treelist-virtual-scrolling). In other words, this is the number of rows above the currently visible ones. |
4444
| `SortDescriptors` | `ICollection<SortDescriptor>` | The currently applied [sorts](slug:treelist-sorting). |
45-
| `TableWidth` | `string` | The sum of all visible column widths. This property changes together with `ColumnStates`. The `OnStateChanged` event does not fire separately for it. |
45+
| `TableWidth` | `string` | The sum of all visible column widths. The initial value is always `null` regardless of the column configuration. The `TableWidth` value changes during column resizing together with `ColumnStates` and the`OnStateChanged` event does not fire separately for it. When you resize a column programmatically, and all other columns already have widths, you must update the `TableWidth` too, otherwise the other columns will resize unexpectedly. |
4646

4747
\* `TItem` is the TreeList model type.
4848

0 commit comments

Comments
 (0)