Completed
Last Updated: 28 Apr 2022 22:37 by Neil
Release 1.1.0
Shaun
Created on: 12 May 2019 18:56
Category: Grid
Type: Feature Request
7
Grid Height flexibility

Currently the blazor grid must be a specific, static height.  If one is not provided, the grid uses a default of 500px.

Kendo grid implementations in other UI frameworks allow for more flexibility in the height of the grid.  It would be great if the blazor implementation could support this as well. 

Two specific scenarios that are valueable:

1) Grid height adjusts to accomodate all of the items in the grid

For other kendo grid implementations, this is typically the case when "Scrollable" is set to false.   If there is a plan to allow toggling scrolling for the blazor grid, then I think that this would come along with that.

2) Ability to set grid height to 100%

With other kendo implementations this is normally done via CSS, and is useful for when you want a "full screen" grid.  This is normally combined with "Scrollable=true" and often combined with Pagination="true" as well.   Currently it's not possible to do this - since the height is defined on the k-grid element, it cannot be overridden with CSS.

2 comments
Neil
Posted on: 28 Apr 2022 22:37

you might also need to add a rule to override the min-height (450px) on the .k-grid class, this prevents empty space under rows

 

.k-grid

{

min-height: fit-content !important;

}

 

or add the min-height override to Martin's example of adding a class to the parent container

 

min-

ADMIN
Marin Bratanov
Posted on: 13 May 2019 04:18
Hello Shaun,

Short version: We have plans to work in this direction and this page will get updated once it gets done. If you haven't already, click the Follow button to get notifications for status changes.

Long version:

At the moment, the grid has a Height property that can take pixel values only. We are considering improving the approach to setting sizes across the board and once it is decided upon, we will release it. Perhaps we will simply change the Height and Width properties to string so you can put any valid CSS dimension there, for example "100%" or "50vw" and so on.

I must note that 100% height is something that is quite tricky for a grid and next to impossible without JS code that will re-calculate dimensions. The main reason for that is that there are several horizontal elements that create a grid - column headers, filter row, footer/pager, in addition to the data rows. The 100% height works in such a way that you can't really have siblings that fill up to 100% height with CSS, you need to calculate their dimensions separately and set them with JS so they add up to the desired height. Since this is not really a good practice in Blazor, it is still to be determined how and even if such a thing can work out.

For the time being, you can try a CSS override like the snippet below. Considering the paragraph above, however, if there are many data rows, the grid will probably stretch to accommodate them, it does not have a constraint in this regard once the default pixel height is removed. Once a container with size in px is encountered, things are likely to work out better, though - hence the .container with explicit height below. If that .container is also set to have a height in percentage, however, the layout is determined by elements further up the DOM and their rules and things can get messy.

<style>
    .container{
        height: 500px;
    }
    .container .k-grid {
        height: 100% !important;
    }
</style>
  
<div class="container">
    <TelerikGrid Data=@MyData>
        the grid goes here
    </TelerikGrid>
  
</div>


On the approach to have the rows determine the height, you can try something like this:

@using Telerik.Blazor.Components.Grid
 
<style>
    .NoHeight {
        height: auto !important;
    }
</style>
 
<TelerikGrid Data="@MyData" Class="NoHeight">
    <TelerikGridColumns>
        <TelerikGridColumn Field="ID"></TelerikGridColumn>
        <TelerikGridColumn Field="TheName" Title="Employee Name"></TelerikGridColumn>
    </TelerikGridColumns>
</TelerikGrid>
 
@functions {
    public IEnumerable<object> MyData = Enumerable.Range(1, 50).Select(x => new { ID = x, TheName = "name " + x });
}

 

Regards,
Marin Bratanov
Progress Telerik UI for Blazor