Skip to content

docs(Grid): Document stacked mode #3164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/grid/columns/auto-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/display-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/frozen.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/multi-column-headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/reorder.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/resize.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
213 changes: 213 additions & 0 deletions components/grid/columns/stacked.md
Original file line number Diff line number Diff line change
@@ -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 `<GridStackedLayoutSettings>`.
* The [`Width` parameter](#stacked-columns-width) of each `<GridStackedLayoutColumn>`.

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
<TelerikGrid DataLayoutMode="@GridDataLayoutMode.Stacked" />
````

## Stacked Columns Count

`ColumnsCount` is a an optional parameter of `<GridStackedLayoutSettings>`, which is a child tag of `<GridSettings>`. 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
<TelerikGrid DataLayoutMode="@GridDataLayoutMode.Stacked">
<GridSettings>
<GridStackedLayoutSettings ColumnsCount="2" />
</GridSettings>
<GridColumns>
<GridColumn Field="@nameof(Product.Name)" />
<GridColumn Field="@nameof(Product.Price)" />
<GridColumn Field="@nameof(Product.Quantity)" />
<GridColumn Field="@nameof(Product.StartDate)" />
<GridColumn Field="@nameof(Product.IsActive)" />
<GridCommandColumn>
<GridCommandButton />
</GridCommandColumn>
</GridColumns>
</TelerikGrid>
````

## Stacked Columns Width

An optional `<GridStackedLayoutColumns>` tag inside `<GridStackedLayoutSettings>` allows you to define custom `Width` for each stacked column (`<GridStackedLayoutColumn>`) 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 `<GridStackedLayoutColumn>` 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
<GridStackedLayoutSettings ColumnsCount="3">
<GridStackedLayoutColumns>
<GridStackedLayoutColumn Width="2fr" />
<GridStackedLayoutColumn Width="1fr" />
<GridStackedLayoutColumn Width="1fr" />
</GridStackedLayoutColumns>
</GridStackedLayoutSettings>

````

## 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

<TelerikMediaQuery Media="(min-width:1200px)" OnChange="@( (bool matches) => IsLargeScreen = matches )" />
<TelerikMediaQuery Media="(min-width:800px)" OnChange="@( (bool matches) => IsMediumScreen = matches )" />
<TelerikMediaQuery Media="(max-width:500px)" OnChange="@( (bool matches) => IsSmallScreen = matches )" />

<TelerikGrid Data="@GridData"
DataLayoutMode="@( IsLargeScreen ? GridDataLayoutMode.Columns : GridDataLayoutMode.Stacked )"
FilterMode="@GridFilterMode.FilterMenu"
EditMode="@GridEditMode.Inline"
Groupable="true"
OnUpdate="@OnGridUpdate"
OnCreate="@OnGridCreate"
SelectionMode="@GridSelectionMode.Multiple"
@bind-SelectedItems="@GridSelectedItems"
ShowColumnMenu="true"
Sortable="true"
Height="90vh">
<GridSettings>
<GridStackedLayoutSettings ColumnsCount="@GridStackedColumnsCount" />
<GridToolBarSettings OverflowMode="@GridToolBarOverflowMode.Scroll" />
</GridSettings>
<GridToolBar>
<GridToolBarAddTool>Add</GridToolBarAddTool>
@if (!IsLargeScreen)
{
<GridToolBarSelectAllTool Text="Select&nbsp;All" />
<GridToolBarSortTool>Sort</GridToolBarSortTool>
<GridToolBarFilterTool>Filter</GridToolBarFilterTool>
<GridToolBarColumnChooserTool>Columns</GridToolBarColumnChooserTool>
<GridToolBarGroupTool>Group</GridToolBarGroupTool>
}
</GridToolBar>
<GridColumns>
<GridCheckboxColumn />
<GridColumn Field="@nameof(Product.Name)" />
<GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:c2}" />
<GridColumn Field="@nameof(Product.Quantity)" DisplayFormat="{0:n0}" />
<GridColumn Field="@nameof(Product.StartDate)" DisplayFormat="{0:d}" />
<GridColumn Field="@nameof(Product.IsActive)" />
<GridCommandColumn Width="120px">
<GridCommandButton Command="Edit" Icon="@SvgIcon.Pencil" />
<GridCommandButton Command="Save" Icon="@SvgIcon.Save" ShowInEdit="true" />
<GridCommandButton Command="Cancel" Icon="@SvgIcon.Cancel" ShowInEdit="true" />
</GridCommandColumn>
</GridColumns>
<DetailTemplate>
<div style="padding:0.5em 0;">DetailTemplate for @context.Name</div>
</DetailTemplate>
</TelerikGrid>

@code {
private int GridStackedColumnsCount => IsSmallScreen ? 1 : 2;

private List<Product> GridData { get; set; } = new();
private IEnumerable<Product> GridSelectedItems { get; set; } = new List<Product>();

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)
2 changes: 1 addition & 1 deletion components/grid/columns/virtual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/visible.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/grid/columns/width.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions components/grid/toolbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down