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
Copy file name to clipboardExpand all lines: components/grid/overview.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -162,7 +162,7 @@ The following table lists Grid parameters, which are not discussed elsewhere in
162
162
| Parameter | Type and Default Value | Description |
163
163
| --- | --- | --- |
164
164
|`Class`|`string`| Additional CSS class for the `<div class="k-grid">` element. Use it to apply custom styles or [override the theme]({%slug themes-override%}). For example, [change the Grid font size]({%slug grid-kb-change-font-size%}). |
165
-
|`Height`|`string`| A height style in [any supported CSS unit]({%slug common-features/dimensions%}). |
165
+
|`Height`|`string`| A height style in [any supported CSS unit]({%slug common-features/dimensions%}). You can also [make the Grid height change automatically with the browser window]({%slug grid-kb-adjust-height-with-browser%}). |
|`Width`|`string`| A width style in [any supported CSS unit]({%slug common-features/dimensions%}). The Grid has no default width, but expands horizontally to fill its container. |
title: Adjust height of the Grid to match with the browser
3
-
description: How to adjust the height of the Grid to match with the browser.
2
+
title: Adjust Grid Height to Match the Browser Viewport Height
3
+
description: Learn different ways to adjust the height of the Telerik Grid for Blazor, so that the component expands and its height takes up all the available free space, depending on the container and the browser window (viewport size).
4
4
type: how-to
5
-
page_title: Adjust Grid height with browser
5
+
page_title: How to Adjust the Grid Height to Fill the Browser Window Size
How to change page size according to the available height? How to hide columns based on screen size?
33
+
This KB article answers the following questions:
27
34
35
+
* How to autosize the Telerik Blazor Grid to match the browser window height?
36
+
* How to change Grid page size, according to the available height? How make the Grid `PageSize` dynamic based on screen size?
37
+
* How to configure a resizeable Grid?
38
+
* How to use several Grids that expand and fill the height of the browser?
39
+
* How to set the `TelerikGrid``Height` relative to the browser viewport size?
40
+
* How to make the Grid height adjust by itself when user resizes the browser? The user should not get a scroll bar of the browser.
41
+
* How to expand the Grid to the maximum available height during browser resizing?
42
+
* How to adjust the Grid `Height` to the remaining space?
28
43
29
44
## Solution
30
45
31
-
An example is available in the following project: [https://github.com/telerik/blazor-ui/tree/master/grid/adjust-height-with-browser](https://github.com/telerik/blazor-ui/tree/master/grid/adjust-height-with-browser).
46
+
The Grid will obey its `Height` parameter value in the same way as a regular HTML `<div>`. The component can apply any [valid CSS dimension unit]({%slug common-features/dimensions%}). If the app layout and CSS styles can make a plain `<div>` resize with the browser viewport or the parent element, then the Grid can behave in the same way too.
47
+
48
+
The following sections demonstrate different ways to make a Grid resize vertically, depending on the available space. The information and samples are applicable to [other Telerik components for Blazor](#environment).
*[Use minimum or maximum height](#apply-minimum-or-maximum-height)
55
+
*[Set `PageSize` depending on the Grig height]()
56
+
57
+
> If the [Grid is using virtual columns]({%slug grid-columns-virtual%}), then its `Height` must be set in pixels and the techniques in this article are not applicable.
58
+
59
+
## Use Percent
60
+
61
+
Use percentage heights to define dimensions as a portion of the parent element.
62
+
63
+
When setting a `height` in percent, keep in mind the following rule: an element with a percentage `height` requires its parent to have an explicit height. The rule applies recursively until a fixed height is reached, or until the `<html>` element is reached.
Enumerable.Range(1, 200).Select(x => new SampleModel() { Id = x, Name = $"Name {x}" });
119
+
120
+
public class SampleModel
121
+
{
122
+
public int Id { get; set; }
123
+
public string Name { get; set; } = string.Empty;
124
+
}
125
+
}
126
+
````
127
+
128
+
## Use CSS calc()
129
+
130
+
Use <ahref="https://developer.mozilla.org/en-US/docs/Web/CSS/calc"target="_blank"><code>calc()</code></a> to set dimensions as a calculation that depends on multiple known sizes. For example, `calc()` is suitable when a Telerik component must occupy the full viewport height minus a known fixed height of a header or footer.
Enumerable.Range(1, 200).Select(x => new SampleModel() { Id = x, Name = $"Name {x}" });
157
+
158
+
public class SampleModel
159
+
{
160
+
public int Id { get; set; }
161
+
public string Name { get; set; } = string.Empty;
162
+
}
163
+
}
164
+
````
165
+
166
+
## Use Telerik Layout Components
167
+
168
+
Using Telerik layout components can spare the need to use custom CSS and make a 100% high nested component occupy the available space in its parent container.
169
+
170
+
>caption Set Grid Height to 100% of resizable container
Enumerable.Range(1, 200).Select(x => new SampleModel() { Id = x, Name = $"Name {x}" });
202
+
203
+
public class SampleModel
204
+
{
205
+
public int Id { get; set; }
206
+
public string Name { get; set; } = string.Empty;
207
+
}
208
+
}
209
+
````
210
+
211
+
## Apply Minimum or Maximum Height
212
+
213
+
You can make the Grid resize automatically, but at the same time, limit how much the component can shrink or expand with some fixed dimensions. Set the Grid `Class` parameter and use `min-height` or `max-height` styles with a custom CSS class.
214
+
215
+
>caption Limit a dynamic Grid Height to minimum and maximum values
Enumerable.Range(1, 200).Select(x => new SampleModel() { Id = x, Name = $"Name {x}" });
238
+
239
+
public class SampleModel
240
+
{
241
+
public int Id { get; set; }
242
+
public string Name { get; set; } = string.Empty;
243
+
}
244
+
}
245
+
````
246
+
247
+
## Set Grid PageSize Depending on the Height
248
+
249
+
You can change the Grid `PageSize` at runtime, so that it is consistent with the Grid height and the available space. Review the complete sample app in GitHub: [https://github.com/telerik/blazor-ui/tree/master/grid/adjust-height-with-browser](https://github.com/telerik/blazor-ui/tree/master/grid/adjust-height-with-browser).
250
+
251
+
## See Also
252
+
253
+
*[Using Dimensions in Telerik Blazor Components]({%slug common-features/dimensions%})
0 commit comments