diff --git a/components/grid/columns/auto-generated.md b/components/grid/columns/auto-generated.md index 02fb8b5023..cc54e72dd2 100644 --- a/components/grid/columns/auto-generated.md +++ b/components/grid/columns/auto-generated.md @@ -5,7 +5,7 @@ description: How to automatically generate Grid columns out of a model. slug: grid-columns-automatically-generated tags: telerik,blazor,grid,column,automatic,automatically,generated,columns published: true -position: 5 +position: 35 --- # Automatically Generated Columns diff --git a/components/grid/columns/checkbox.md b/components/grid/columns/checkbox.md index 4468e4df68..d84371d470 100644 --- a/components/grid/columns/checkbox.md +++ b/components/grid/columns/checkbox.md @@ -5,7 +5,7 @@ description: Configuration options for the Telerik Blazor Grid Checkbox Column slug: components/grid/columns/checkbox tags: telerik,blazor,grid,column,selection published: True -position: 2 +position: 10 --- # Grid Checkbox Column diff --git a/components/grid/columns/command.md b/components/grid/columns/command.md index 5d8fafd63e..a34724a2e8 100644 --- a/components/grid/columns/command.md +++ b/components/grid/columns/command.md @@ -5,7 +5,7 @@ description: Command buttons per row in Grid for Blazor. slug: components/grid/columns/command tags: telerik,blazor,grid,column,command published: True -position: 1 +position: 5 --- # Grid Command Column diff --git a/components/grid/columns/display-format.md b/components/grid/columns/display-format.md index 28afb0429c..3be248c581 100644 --- a/components/grid/columns/display-format.md +++ b/components/grid/columns/display-format.md @@ -5,7 +5,7 @@ description: Use C# Format string to display values in the Grid for Blazor. slug: grid-columns-displayformat tags: telerik,blazor,grid,column,display,format published: True -position: 2 +position: 15 --- # Column Display Format diff --git a/components/grid/columns/frozen.md b/components/grid/columns/frozen.md index 84b3758a53..c8707ccea6 100644 --- a/components/grid/columns/frozen.md +++ b/components/grid/columns/frozen.md @@ -5,7 +5,7 @@ description: How to freeze grid columns so they are always visible in a scrollab slug: grid-columns-frozen tags: telerik,blazor,grid,column,freeze,frozen published: true -position: 5 +position: 40 --- # Frozen Columns diff --git a/components/grid/columns/menu.md b/components/grid/columns/menu.md index 6ece23e08d..012a69c618 100644 --- a/components/grid/columns/menu.md +++ b/components/grid/columns/menu.md @@ -5,7 +5,7 @@ description: Use the Column Menu for the Grid slug: grid-column-menu tags: telerik,blazor,grid,column,columns,menu published: True -position: 20 +position: 55 --- # Column Menu diff --git a/components/grid/columns/multi-column-headers.md b/components/grid/columns/multi-column-headers.md index 3fd66f2cac..0016ab1d2d 100644 --- a/components/grid/columns/multi-column-headers.md +++ b/components/grid/columns/multi-column-headers.md @@ -5,7 +5,7 @@ description: Stack multiple columns under a single header in the data grid for B slug: grid-columns-multiple-column-headers tags: telerik,blazor,grid,column,multi,multiple,headers published: True -position: 25 +position: 60 --- # Multi-Column Headers diff --git a/components/grid/columns/reorder.md b/components/grid/columns/reorder.md index fac5fc7a47..2135d1cee6 100644 --- a/components/grid/columns/reorder.md +++ b/components/grid/columns/reorder.md @@ -5,7 +5,7 @@ description: Drag to reorder columns in the Grid for Blazor. slug: components/grid/columns/reorder tags: telerik,blazor,grid,column,reorder,drag published: True -position: 2 +position: 25 --- # Reorder Columns diff --git a/components/grid/columns/resize.md b/components/grid/columns/resize.md index b79deed870..06a9092f28 100644 --- a/components/grid/columns/resize.md +++ b/components/grid/columns/resize.md @@ -5,7 +5,7 @@ description: Drag to resize columns in the Grid for Blazor. slug: components/grid/columns/resize tags: telerik,blazor,grid,column,resize,drag published: True -position: 3 +position: 20 --- # Resize Columns diff --git a/components/grid/columns/stacked.md b/components/grid/columns/stacked.md new file mode 100644 index 0000000000..98bf967b0a --- /dev/null +++ b/components/grid/columns/stacked.md @@ -0,0 +1,213 @@ +--- +title: Stacked +page_title: Grid - Stacked Columns +description: How to adapt the Grid on small screens and display the values of one data item vertically instead of horizontally. +slug: grid-columns-stacked +tags: telerik,blazor,grid,column,stacked +published: true +position: 37 +--- + +# Stacked Columns + +Stacked columns is an adaptive Grid feature that allows the component to display data item values vertically in one or more cards, instead of horizontally in classic table cells. This facilitates browsing the Grid data on narrow screens like mobile phones in portrait orientation. + +The Grid stacked columns functionality depends on three configuraton settings: + +* The [`DataLayoutMode` parameter](#data-layout-mode) of the Grid. +* The [`ColumnsCount` parameter](#stacked-columns-count) of ``. +* The [`Width` parameter](#stacked-columns-width) of each ``. + +Only the `DataLayoutMode` parameter is required to use stacked Grid columns. + +## Data Layout Mode + +The show stacked Grid columns, set the `DataLayoutMode` component parameter to `GridDataLayoutMode.Stacked`. The default parameter value is `GridDataLayoutMode.Columns`. + +>caption Enable stacked columns in the Grid + +````RAZOR.skip-repl + +```` + +## Stacked Columns Count + +`ColumnsCount` is a an optional parameter of ``, which is a child tag of ``. The `ColumnsCount` parameter sets how many stacked columns will show. The default value is `1`, which means that all data row values will display one below the other in a single column. + +When using multiple stacked columns, the data row values are arranged first horizontally and then vertically. The following code snippet uses 2 stacked columns, so that the odd columns (`Name`, `Quantity` and `IsActive`) display in the first stacked column, while the even columns (`Price`, `StartDate`, and the command buttons) display in the second stacked column. + +>caption Display 2 stacked columns in the Grid + +````RAZOR.skip-repl + + + + + + + + + + + + + + + +```` + +## Stacked Columns Width + +An optional `` tag inside `` allows you to define custom `Width` for each stacked column (``) when there is more than one. The default width value is `"1fr"`, which means one equal fraction of the available horizontal space. The stacked Grid columns use the [CSS Grid concept](https://css-tricks.com/snippets/css/complete-guide-grid/) for HTML rendering. + +> When using `` instances, the number of these tags must match the `ColumnsCount` value. + +The code snippet below uses 3 stacked columns. The first one is twice as wide as the others. + +>caption Set custom widths to the stacked Grid columns + +````RAZOR.skip-repl + + + + + + + + +```` + +## Integration with Other Features + +When the Grid is in `Stacked` data layout mode, it does not render column headers. As a result, column features like sorting, filtering, grouping, locking are not available through the classic Grid UI. Instead, use [ToolBar command tools](slug:components/grid/features/toolbar#command-tools) to enable the same functionality through different UI. + +Hierarchy relies on an expand/collapse button, which is below the stacked table row content. + +## Example + +The following sample shows how to: + +* Enable and disable column stacking, depending on the viewport width. +* Display 1 or 2 stacked columns, depending on the viewport width. +* Render ToolBar tools for column operations only when the Grid is in `Stacked` data layout mode. + +>caption Using stacked data layout mode in the Blazor Grid + +````RAZOR +@using System.ComponentModel.DataAnnotations + + + + + + + + + + + + Add + @if (!IsLargeScreen) + { + + Sort + Filter + Columns + Group + } + + + + + + + + + + + + + + + +
DetailTemplate for @context.Name
+
+
+ +@code { + private int GridStackedColumnsCount => IsSmallScreen ? 1 : 2; + + private List GridData { get; set; } = new(); + private IEnumerable GridSelectedItems { get; set; } = new List(); + + private bool IsLargeScreen { get; set; } + private bool IsMediumScreen { get; set; } + private bool IsSmallScreen { get; set; } + + private int LastId { get; set; } + + private void OnGridCreate(GridCommandEventArgs args) + { + var createdItem = (Product)args.Item; + + createdItem.Id = ++LastId; + + GridData.Insert(0, createdItem); + } + + private void OnGridUpdate(GridCommandEventArgs args) + { + var updatedItem = (Product)args.Item; + var originalItemIndex = GridData.FindIndex(i => i.Id == updatedItem.Id); + + if (originalItemIndex != -1) + { + GridData[originalItemIndex] = updatedItem; + } + } + + protected override void OnInitialized() + { + for (int i = 1; i <= 5; i++) + { + GridData.Add(new Product() + { + Id = ++LastId, + Name = $"Product {LastId}", + Price = Random.Shared.Next(0, 100) * 1.23m, + Quantity = Random.Shared.Next(0, 10000), + StartDate = DateTime.Now.AddDays(-Random.Shared.Next(60, 1000)), + IsActive = LastId % 2 != 0 + }); + } + } + + public class Product + { + public int Id { get; set; } + [Required] + public string Name { get; set; } = string.Empty; + public decimal? Price { get; set; } + public int Quantity { get; set; } + [Required] + public DateTime? StartDate { get; set; } = DateTime.Today; + public bool IsActive { get; set; } + } +} +```` + +## See also + +* [Live demo: Adaptive Grid](https://demos.telerik.com/blazor-ui/grid/adaptive) +* [Live demo: Grid and MediaQuery Integration](https://demos.telerik.com/blazor-ui/mediaquery/grid-integration) diff --git a/components/grid/columns/virtual.md b/components/grid/columns/virtual.md index ce273e0497..1b96eeb682 100644 --- a/components/grid/columns/virtual.md +++ b/components/grid/columns/virtual.md @@ -5,7 +5,7 @@ description: How to add virtual columns to a scrollable Grid. slug: grid-columns-virtual tags: telerik,blazor,grid,column,virtual,scrolling published: true -position: 5 +position: 45 --- # Virtualized Columns diff --git a/components/grid/columns/visible.md b/components/grid/columns/visible.md index 1eb6c67f93..197d4c0563 100644 --- a/components/grid/columns/visible.md +++ b/components/grid/columns/visible.md @@ -5,7 +5,7 @@ description: Hide Grid columns. slug: grid-columns-visible tags: telerik,blazor,grid,column,visible published: True -position: 15 +position: 50 --- # Visible Columns diff --git a/components/grid/columns/width.md b/components/grid/columns/width.md index c5c151a335..b105729279 100644 --- a/components/grid/columns/width.md +++ b/components/grid/columns/width.md @@ -5,7 +5,7 @@ description: Column width behavior in Grid for Blazor. slug: grid-columns-width tags: telerik,blazor,grid,column,width published: True -position: 4 +position: 30 --- # Grid Column Width diff --git a/components/grid/toolbar.md b/components/grid/toolbar.md index 718d1ca8b2..0cadc0c16c 100644 --- a/components/grid/toolbar.md +++ b/components/grid/toolbar.md @@ -22,17 +22,18 @@ The [Blazor Grid](https://demos.telerik.com/blazor-ui/grid/overview) provides se | Tool Name | Tool Tag | Description | | --- | --- | --- | -| Add | `GridToolBarAddTool` | An add command that fires the [`OnAdd` event](slug:grid-editing-overview#events). | -| Cancel | `GridToolBarCancelEditTool` | Cancels the changes for the selected row. [Row selection](slug:grid-selection-row) and [`Inline`](slug:grid-editing-inline) or [`Popup`](slug:grid-editing-popup) editing mode are required. | -| CsvExport | `GridToolBarCsvExportTool` | An export command for CSV files that fires the [`OnBeforeExport` event](slug:grid-export-events#onbeforeexport). | -| Delete | `GridToolBarDeleteTool` | Deletes the selected row. Row selection and `Inline` or `Popup` editing mode are required. | -| Edit | `GridToolBarEditTool` | Enters edit mode for the selected row. Row selection and `Inline` or `Popup` editing mode are required. | -| ExcelExport | `GridToolBarExcelExportTool` | An export command for Excel files that fires the [`OnBeforeExport` event](slug:grid-export-events#onbeforeexport). | -| Filter | `GridToolBarFilterTool` | A toggle button in the Grid’s toolbar that opens a UI option for filtering. On desktop screens, it displays a popup with a filter menu; on mobile devices, it renders an `ActionSheet`. The filter component has two views: one for selecting the column to filter, and another for applying the filter to the selected column. The tool also exposes an `Icon` parameter that allows you to override the default icon. | -| Group | `GridToolBarGroupTool` | A toggle button in the Grid’s toolbar that opens a popup listing the groupable columns—click a column to group by it. On mobile devices, the popup is rendered as an `ActionSheet`. The tool also exposes an `Icon` parameter that allows you to override the default icon. | -| Save | `GridToolBarSaveEditTool` | Saves the changes for the selected row. Row selection and `Inline` or `Popup` editing mode are required. | -| Sort | `GridToolBarSortTool` | A toggle button in the Grid’s toolbar that opens a popup listing the sortable columns—click a column to sort by it. On mobile devices, the popup is rendered as an `ActionSheet`. The tool also exposes an `Icon` parameter that allows you to override the default icon. | -| SearchBox | `GridToolBarSearchBoxTool` | A searchbox that filters multiple Grid columns simultaneously. | +| Add | `GridToolBarAddTool` | An `Add` command button that fires the [`OnAdd` event](slug:grid-editing-overview#events). | +| Cancel | `GridToolBarCancelEditTool` | A `Cancel` command button that applies to the row in edit mode and fires [`OnCancel`](slug:grid-editing-overview#events). [`Inline`](slug:grid-editing-inline) or [`Popup`](slug:grid-editing-popup) editing mode is required. | +| CsvExport | `GridToolBarCsvExportTool` | A `CsvExport` command for CSV files that fires the [`OnBeforeExport` event](slug:grid-export-events#onbeforeexport). | +| Delete | `GridToolBarDeleteTool` | A `Delete` command for the selected row that fires [`OnDelete`](slug:grid-editing-overview#events). Row selection and editing are required. | +| Edit | `GridToolBarEditTool` | An `Edit` command button for the selected row that fires [`OnEdit`](slug:grid-editing-overview#events). Row selection and `Inline` or `Popup` editing mode are required. | +| ExcelExport | `GridToolBarExcelExportTool` | An `ExcelExport` command for Excel files that fires the [`OnBeforeExport` event](slug:grid-export-events#onbeforeexport). | +| Filter | `GridToolBarFilterTool` | A toggle button that opens UI for filtering. On desktop screens, it displays a popup with a filter menu; on mobile devices, it renders an `ActionSheet`. The filter component has two views: one for selecting the column to filter, and another for applying the filter to the selected column. The tool also exposes an `Icon` parameter that allows you to override the default icon. | +| Group | `GridToolBarGroupTool` | A toggle button that opens a list of the groupable columns. Click a column to group by it. On mobile devices, the popup renders as an `ActionSheet`. The tool also exposes an `Icon` parameter that allows you to override the default icon. | +| Save | `GridToolBarSaveEditTool` | A `Save` command button for the row in edit mode that fires [`OnUpdate` or `OnCreate`](slug:grid-editing-overview#events). [`Inline`](slug:grid-editing-inline) or [`Popup`](slug:grid-editing-popup) editing mode is required. | +| Select All | `GridToolBarSelectAllTool` | A checkbox that selects all rows, according to the [Grid Checkbox column](slug:components/grid/columns/checkbox) configuration. | +| Sort | `GridToolBarSortTool` | A toggle button that opens a list of the sortable columns. Click a column to sort by it. On mobile devices, the popup renders as an `ActionSheet`. The tool also exposes an `Icon` parameter that allows you to override the default icon. | +| SearchBox | `GridToolBarSearchBoxTool` | A [searchbox that filters multiple string columns](slug:grid-searchbox) simultaneously. | ### Layout Tools