This example implements a DevExpress Blazor Grid column layout that adapts to different desktop screen sizes as follows:
- Columns occupy available space
- Cell content is always visible (word trimming/wrapping is disabled)
-
Bind our Blazor Grid to a data source and populate the component with columns.
-
Use the Grid.TextWrapEnabled property to disable word wrapping.
-
Identify columns with fixed content width (for instance, ID, Date, Name). For "fixed content width" columns, assign maximum content length to MinWidth (Width property must not be set). This configuration ensures that a column does not shrink below a specified limit but can stretch on wide screens.
-
For remaining columns, set Width to
0px. -
Call the AutoFitColumnWidths method to adjust zero-width columns to content and stretch fixed-width columns.
IGrid Grid { get; set; }
List<string> FixedWidthColumnCaptions = new List<string> { "ID", "First Name",
"Last Name", "Honorific", "Occupation" };
protected override void OnAfterRender(bool firstRender) {
if (firstRender) {
Grid.BeginUpdate();
foreach (var column in Grid.GetColumns()) {
if (FixedWidthColumnCaptions.Contains(column.Caption)) {
column.MinWidth = 100;
}
else {
column.Width = "0px";
}
}
Grid.EndUpdate();
Grid.AutoFitColumnWidths();
}
}(you will be redirected to DevExpress.com to submit your response)
