Blazor Grid Size
The Ignite UI for Blazor Size feature in Blazor Grid allows users to control the spacing and layout of data within the IgbGrid
. By changing --ig-size
, you can significantly improve the user experience when interacting with large amounts of content. They can choose from three size options:
--ig-size-large
--ig-size-medium
--ig-size-small
Blazor Grid Size Example
Usage
As you can see in the demo above, the IgbGrid
provides three size options: small, medium and large. The code snippet below shows how to set --ig-size
either inline or part of a CSS class:
.gridSize {
--ig-size: var(--ig-size-medium);
}
<IgbGrid Class="gridSize" Data=northwindEmployees @ref=grid>
</IgbGrid>
And now let's see in details how each option reflects on the IgbGrid
component. When you switch between different size options the height of each IgbGrid
element and the corresponding paddings will be changed. Also if you want to apply custom column Width
, please consider the fact that it must be bigger than the sum of left and right padding.
- large - this is the default
IgbGrid
size with the lowest intense and row height equal to50px
. Left and Right paddings are24px
; Minimal columnWidth
is80px
; - medium - this is the middle intense size with
40px
row height. Left and Right paddings are16px
; Minimal columnWidth
is64px
; - small - this is the size with highest intense and
32px
row height. Left and Right paddings are12px
; Minimal columnWidth
is56px
;
[!Note] Please keep in mind that currently you can not override any of the sizes.
Let's now continue with our sample and see in action how the --ig-size
is applied. Let's first add a button which will help us to switch between each size:
<div class="options vertical">
<IgbPropertyEditorPanel
DescriptionType="WebGrid"
IsHorizontal="true"
IsWrappingEnabled="true"
Name="PropertyEditor"
@ref="propertyEditor">
<IgbPropertyEditorPropertyDescription
Name="SizeEditor"
@ref="sizeEditor"
Label="Grid Size:"
ValueType="PropertyEditorValueType.EnumValue"
DropDownNames="@(new string[] { "Small", "Medium", "Large" })"
DropDownValues="@(new string[] { "Small", "Medium", "Large" })"
ChangedScript="WebGridSetGridSize">
</IgbPropertyEditorPropertyDescription>
</IgbPropertyEditorPanel>
</div>
Now we can add the markup.
<div class="container vertical">
<div class="container vertical fill">
<IgbGrid
AutoGenerate="false"
Data="InvoicesData"
AllowFiltering="true"
Id="grid"
Name="grid"
@ref="grid">
<IgbColumn Field="CustomerName" Header="Customer Name" Sortable="true" HasSummary="true" DataType="GridColumnDataType.String"></IgbColumn>
<IgbColumn Field="Country" Header="Country" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="City" Header="City" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="Address" Header="Address" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="PostalCode" Header="Postal Code" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="Salesperson" Header="Sales Person" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="ShipperName" Header="Shipper Name" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="OrderDate" Header="Order Date" DataType="GridColumnDataType.Date" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="ProductID" Header="ID" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="ProductName" Header="Name" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="UnitPrice" Header="Unit Price" DataType="GridColumnDataType.Number" Sortable="true" HasSummary="true" Filterable="false"></IgbColumn>
<IgbColumn Field="Quantity" Header="Quantity" DataType="GridColumnDataType.Number" Sortable="true" HasSummary="true" Filterable="false"></IgbColumn>
<IgbColumn Field="Discontinued" Header="Discontinued" DataType="GridColumnDataType.Boolean" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="Discontinued" Header="Discontinued" DataType="GridColumnDataType.Boolean" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="ShipName" Header="Name" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="ShipCountry" Header="Country" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"> </IgbColumn>
<IgbColumn Field="ShipCity" Header="City" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
<IgbColumn Field="ShipPostalCode" Header="Postal Code" DataType="GridColumnDataType.String" Sortable="true" HasSummary="true"></IgbColumn>
</IgbGrid>
</div>
</div>
Finally, let's provide the necessary logic in order to actually apply the size:
@code {
*** In JavaScript ***
igRegisterScript("WebGridSetGridSize", (sender, evtArgs) => {
var newVal = evtArgs.newValue.toLowerCase();
var grid = document.getElementById("grid");
grid.style.setProperty('--ig-size', `var(--ig-size-${newVal})`);
}, false);
}
Another option that IgbGrid
provides for you, in order to be able to change the height of the rows in the IgbGrid
, is the property RowHeight
. So let's see in action how this property affects the IgbGrid
layout along with the --ig-size
.
Please keep in mind the following:
--ig-size
CSS variable will have no impact on row height if there isRowHeight
specified.--ig-size
will affect all of the rest elements in the Grid, as it has been described above.
We can now extend our sample and add RowHeight
property to the IgbGrid
:
<IgbGrid
@ref="grid"
Id="grid"
Class="gridSize"
Width="100%"
Height="100%"
AutoGenerate="true"
Data="northwindEmployees"
RowHeight="rowHeight">
</IgbGrid>
@code {
private string rowHeight = "80px";
}
API References
Additional Resources
- Virtualization and Performance
- Editing
- Paging
- Filtering
- Sorting
- Summaries
- Column Pinning
- Column Resizing
- Selection
- Searching
Our community is active and always welcoming to new ideas.