Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo Angular 2 Grid Height

I want my grid to have a dynamic height. Before with angular 1 and kendo i would do like this.

<kendo-grid id="grid" options="entityGrid.gridOptions"></kendo-grid>

With the following CSS:

#grid {
    height: calc(100% - 1em);
}

But with Kendo grid for angular2 when i try this it wont work.

<kendo-grid id="grid"
            [data]="entityGrid?.view | async"
            [scrollable]="'virtual'">
 </kendo-grid>
like image 422
Nbergk Avatar asked Nov 24 '16 08:11

Nbergk


People also ask

How do I change the row height in kendo grid?

To adjust the size of the rows in both the body and the header, use CSS and specify the height and padding properties for the th elements inside the thead and tr , and the td elements inside the tbody of the Grid.

How is AG grid height dynamically calculated?

You can use ag-grid feature AutoHeight = true in the column Configuration. or if you want to calculate the height dynamically you should use getRowHeight() callback and create DOM elements like div and span , and add your text in it, then the div will give the OffsetHeight for it then you wont see any cropping of data/ ...

How do I make my Kendo grid responsive?

The responsive features of the Kendo UI Grid for Angular are: Responsive columns—Based on the viewport width, the visibility of the Grid columns toggles. Responsive height—Based on the height setting (for example, "100%" ), the Grid adjusts its size depending on the height of its container.


2 Answers

When using scrolling (and static headers), the grid content area needs to have a height, too. Computing it dynamically based on the page is not supported at this time, and is not going to work with angular-universal. You can log this as a feature request on the kendo-angular2 repo, so that it is considered for implementation.

That said, you can use the following hack to make it work:

encapsulation: ViewEncapsulation.None,
styles: [
  `kendo-grid {
    height: calc(100% - 3em);
    margin-top: 3em;
  }
  kendo-grid .k-grid-content {
    height: calc(100% - 46px);
  }`
],

This will pass the styles in the component itself. The value 46px is the size of the header, and 3em is your desired offset.

See this plunkr example for a working demo.

like image 150
Alex Gyoshev Avatar answered Nov 09 '22 03:11

Alex Gyoshev


I was able to set dynamic height with following configuration

<kendo-grid class="grid"
   [kendoGridGroupBinding]="data"
   [ngStyle]="gridHeight"
</kendo-grid>

In TS file

public gridHeight = {
   height: 'calc(100vh - 140px)'
};

You can set height as per your requirement from TS

like image 42
Pranay Kharsamble Avatar answered Nov 09 '22 04:11

Pranay Kharsamble