RevoGrid provides the ability to automatically adjust the width of columns to fit the table’s width.
This is particularly useful when you have fewer columns than needed to enable the horizontal scrollbar, and you want to distribute the available space evenly or according to specific criteria.
In this article, we’ll walk you through the process of implementing column stretching in RevoGrid using the ColumnStretchPlugin. We’ll also explore the different configurations available for stretching the columns.
Column stretching is a feature which allows you to automatically adjust the width of columns to fit the entire width of the table. The width of each column is calculated based on the number of columns and their respective sizes, ensuring the grid’s width is fully utilized. This feature is especially useful when working with a small number of columns.
Columns marked with autoSize: true participate in stretching. Measured content widths are lower bounds, and remaining space is distributed up to each column’s maxSize. Disabling stretch restores the measured widths.
Columns with an explicit size and no autoSize remain fixed in all mode. If the combined content widths exceed the grid, columns retain their measured widths and the grid scrolls horizontally.
RevoGrid supports different types of stretch configurations through the StretchConfig type:
'none': No column stretching will be applied. Columns retain their default width.
'last': Only the last column will stretch to fill the remaining width.
'all': All columns will stretch evenly to fill the table’s width.
number: A specific column (by index) will stretch to fill the remaining width.
To stretch only the last column:
1
grid.additionalData = { stretch:'last' };
To stretch a specific column by index (e.g., the second column):
1
grid.additionalData = { stretch:1 };
To stretch all columns evenly:
1
grid.additionalData = { stretch:'all' };
By using the ColumnStretchPlugin, you can easily manage the width of columns in RevoGrid, making sure your table layout looks clean and is fully utilized. Whether you want to stretch all columns evenly or just the last one, this plugin offers flexibility to suit your needs.
Experiment with the different stretch configurations to see which works best for your data grid!
Core places colPinEnd columns at the right edge of the grid. When fixed-width columns leave unused space, you can keep the pinned-end columns directly after the regular columns with a scoped CSS rule:
1
revo-grid.adjacent-pinned-end
2
.viewports
3
>revogr-viewport-scroll.rgCol:not([row-header]) {
4
flex-grow:0;
5
}
Add class="adjacent-pinned-end" to that grid. ColumnStretchPlugin uses the grid’s available width, so this layout also supports stretching flexible columns and repeated grid resizes. Explicitly sized pinned columns retain their configured width.