You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This article explains how the grid column width behaves depending on the settings applied by the developer.
13
+
This article explains how the Grid behaves, depending on the set column widths.
14
14
15
-
You can set the grid column `Width` parameter in any CSS unit, such as `px`, `%`, `vw`, `em`, `rem`. You can read more on how to set sizes in Telerik components in the [Dimensions](slug:common-features/dimensions) article. You must, however, provide the unit so that the browser can understand it.
15
+
## Basics
16
16
17
-
With regard to the widths of its columns, the scrollable (default) Grid typically behaves as any regular HTML table with a `table-layout: fixed` and `width: 100%`.
17
+
The Grid renders separate HTML `<table>` elements for its header, data, and footer areas. This allows users to scroll the data area vertically, while the header and footer areas remain visible at all times. The Grid tables apply `table-layout: fixed` and `width: 100%` CSS styles to ensure column alignment between the three areas.
18
18
19
-
* When all column widths are explicitly set and the cumulative column width is greater than the available Grid width, a horizontal scrollbar appears and all set column widths are respected.
19
+
You can set the Grid column `Width` parameter in any CSS unit, such as `px`, `%`, `vw`, `em`, `rem`. Unit-less `Width` values are not supported. You can read more on how to set sizes in Telerik components in the [Dimensions](slug:common-features/dimensions) article.
20
20
21
-
* When all column widths are explicitly set and the cumulative column width is less than the available Grid width, the remaining width is distributed evenly between all columns.
21
+
## Column Width Behavior
22
22
23
-
* When only some column widths are set and the cumulative width of the columns with set widths is greater than the available Grid width, a horizontal scrollbar appears and all set column widths are respected. Columns with no set width are invisible as their width is `0`.
23
+
The Grid column width settings can vary and result in the following configurations and behavior:
24
24
25
-
* When only some column widths are set and the cumulative width of columns with set widths is less than the available Grid width, the widths of the columns with a set width are respected and the remaining width is distributed evenly between the other columns.
25
+
* All Grid columns have set widths:
26
+
* The sum of the column widths exceeds the Grid component width. The Grid renders a horizontal scrollbar. All column widths match their settings.
27
+
* The sum of the column widths is less than the Grid width. All columns expand evenly to take up the available space in the Grid.
28
+
* Only some Grid columns have set widths:
29
+
* The columns that have widths take up less than the Grid component width. The applied column widths match the component settings. The remaining width-less columns shrink or expand, depending on the remaining space. A horizontal scrollbar may appears only if the columns that have widths exceed the Grid width. In this case the remaining columns will disappear.
30
+
* The columns that have widths take up more than the Grid component width. The applied column widths match the component settings. A horizontal scrollbar appears. All columns without widths shrink to zero width and disappear.
31
+
* No column has a set width: all columns are equally wide. They shrink and expand, depending on the Grid width.
26
32
27
-
* When no column widths are set, the available width is distributed evenly between all Grid columns.
* To allow the users to auto-fit the column widths to the content, enable [column resizing](slug:components/grid/columns/resize) - a double click on the border between the headers will have the grid adjust the column width according to the size of the data, headers and footers content. It is also possible to [auto-fit columns programmatically](slug:components/grid/columns/resize#autofit-columns).
35
+
<style>
36
+
.multi-dimensonal-tableth {
37
+
padding: 8px;
38
+
background: var(--bg-table-th-color);
39
+
color: var(--table-th-color);
40
+
font-weight: 700;
41
+
text-align: left;
42
+
font-size: 18px;
43
+
}
44
+
</style>
45
+
46
+
<tableclass="multi-dimensonal-table">
47
+
<tr><th>Explicit Column Widths<br> \ <br> Columns with Widths</th><th>Exceed the Grid Width</th><th>Subceed the Grid Width</th></tr>
48
+
<tr><th>All</th><td>The Grid renders a horizontal scrollbar. All column widths match their settings.</td><td>All columns expand evenly to take up the available space in the Grid.</td></tr>
49
+
<tr><th>Some</th><td>The applied column widths match the component settings. A horizontal scrollbar appears. All columns without widths shrink to zero width and disappear.</td><td>The applied column widths match the component settings. The remaining width-less columns shrink or expand, depending on the remaining space. A horizontal scrollbar may appears only if the columns that have widths exceed the Grid width. In this case the remaining columns will disappear.</td></tr>
50
+
<tr><th>None</th><td>All columns are equally wide. They shrink and expand, depending on the Grid width.</td><td>All columns are equally wide. They shrink and expand, depending on the Grid width.</td></tr>
51
+
</table>
52
+
53
+
To allow the users to adjust or auto-fit the column widths to the content, enable [Grid column resizing](slug:components/grid/columns/resize). You can also [resize columns through the Grid state](slug:grid-state#setstateasync) or [auto-fit columns programmatically](slug:components/grid/columns/resize#autofit-columns).
54
+
55
+
> Single table rendering and automatic table layout are not supported.
56
+
57
+
## Recommendations
58
+
59
+
For predictable and user-friendly behavior, consider the following Grid configuration:
60
+
61
+
* If the Grid has a fixed width and you need horizontal scrolling, set widths to all columns. Use absolute units that do not depend on the browser viewport size.
62
+
* If the Grid does not need horizontal scrolling and is not likely to shrink too much, then leave at least one column without a width. This ensures that all set column widths are respected and the width-less columns take up the remaining space.
63
+
* If the Grid width is unpredictable and the width-less columns may shrink too much, then apply a `min-width` style to the Grid tables, according to the exaple below.
64
+
65
+
>caption Apply a minimum width to the Grid table in a responsive layout
0 commit comments