[!Note] Please note that this control has been deprecated and replaced with the Grid component, and as such, we recommend migrating to that control. This will not be receiving any new features, bug fixes will be deprioritized. For help or questions on migrating your codebase to the Data Grid, please contact support.
Blazor Grid Column Pinning Overview
The Ignite UI for Blazor Data Grid supports the ability to pin columns, allowing the end users to lock a column in a particular column order.
A column or multiple columns can be pinned to the left-hand or right-hand side of the Data Grid. In addition, you can change the pin state of the columns by utilizing the PinColumn
function.
Blazor Grid Column Pinning Example
The Column Pinning API in the Data Grid can be enabled by setting either a column's Pinned
property, or when setting it by utilizing the PinColumn
function of the grid.
The Pinned
property has three options:
- Left - enabling
Left
will position pinned columns to the left-hand side of the grid. - Right - enabling
Right
will position pinned columns to the right side of the grid. - None - enabling
None
will unpin a column and reposition its default placement within the grid.
Unpinned columns that are adjacent to pinned columns will still maintain horizontal scrolling.
The PinColumn
function contains two required parameters. The first parameter is the column to be pinned, and the second is with the PinnedPositions
enumeration setting.
Code Snippet
The following code demonstrates how to implement column pinning in the Blazor Data Grid with column pinning by using the Pinned
property and PinColumn
function:
<IgbDataGrid Height="100%" Width="100%"
DefaultColumnMinWidth="120"
DataSource="@DataSource"
AutoGenerateColumns="false"
@ref="DataGridRef">
@*Columns Pinned Left*@
<IgbTextColumn Field="ID" Pinned="PinnedPositions.Left" />
<IgbTextColumn Field="FirstName" Pinned="PinnedPositions.Left" />
<IgbTextColumn Field="LastName" Pinned="PinnedPositions.Left" />
@*Columns Unpinned*@
<IgbDateTimeColumn Field="Birthday" Pinned="PinnedPositions.None" />
<IgbNumericColumn Field="Age" Pinned="PinnedPositions.None" />
<IgbImageColumn Field="CountryFlag" Pinned="PinnedPositions.None" />
@*Columns Pinned Right*@
<IgbTextColumn Field="Street" Pinned="PinnedPositions.Right" />
<IgbTextColumn Field="City" Pinned="PinnedPositions.Right" />
<IgbTextColumn Field="Country" Pinned="PinnedPositions.Right" />
</IgbDataGrid>
Toolbar's Column Pinning UI
The Column Pinning UI is accessible within the IgbDataGridToolbar
component separate from the grid. For this purpose all we have to do is set the toolbar's columnPinning
property to true. The toolbar will then display a IgbButton
, when clicked, will display the column pinning UI. This button also displays the total of pinned-left columns. If the toolbar is not created, enabling the columnPinning
property will have no effect and hide the button.
The IgbDataGridToolbar
provides additional properties such as adding a title to the toolbar by using the ToolbarTitle
property, placing text in the IgbButton
by setting the columnPinningText
property, and adding a title header to the column hiding UI by setting columnPinningTitle
.
Demo
Code Snippet
<IgbDataGridToolbar TargetGrid="DataGridRef"
ToolbarTitle="Grid Toolbar Title"
ColumnPinning="true"
ColumnPinningText="Pinning"
ColumnPinningTitle="Column Pinning" />
<IgbDataGrid Height="100%" Width="100%"
@ref="DataGridRef"
DataSource="DataSource" />
@code {
private IgbDataGrid grid;
public IgbDataGrid DataGridRef
{
get
{
return grid;
}
set
{
grid = value;
StateHasChanged();
}
}
}
API References
IgbButton
IgbDataGridToolbar
PinColumn
PinnedPositions
Pinned