This is a migrated thread and some comments may be shown as answers.

Automatic height resize on window resize

3 Answers 686 Views
Grid
This is a migrated thread and some comments may be shown as answers.
EGrop
Top achievements
Rank 1
EGrop asked on 10 May 2019, 10:54 AM

Hi!

In my application I need a feature whenever the user changes the windows size, I need to change the grid's height according to this resize event. This way the grid's content will be scrollable and not the entire grid.

My solution works perfectly when the windows height is decreased. The problem occurs if I want to increase the window's height because I don't know how much height does the grid need to display all of his rows (non virtual scroll). Therefore when the grid has for example only 1 datarow, but the available space is much more there will be a lot of empty space between the grid's datarow and the pager.

My question is how can I know that how much height does the grid need to display it's datarows? Or (if it's not possible) how can I avoid the problem which I described before?

Example application:

https://stackblitz.com/edit/grid-auto-height-resize

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Svet
Telerik team
answered on 14 May 2019, 09:51 AM
Hi,

Thank you for the demonstrated example.

Indeed, some custom logic will have to be implemented in order to achieve the desired behavior. For example, the required Grid height can be calculated based on the number of its rows and the height of a row (the heights of the Grid header and footer will also need to be added to the total height of the Grid). The number of the rows should be equal to the number of items currently loaded in the Grid. The default height of a Grid row is 36 px. We need to ensure, that the height of all rows is equal in order for the calculation to be correct. This can be achieved using the following CSS:
encapsulation: ViewEncapsulation.None,
    styles: [`
        .k-grid tbody td {
            white-space: nowrap;
            line-height: 20px;
            padding: 8px 12px;
        }
    `]

I hope this points you in the right direction of achieving the desired functionality. Let me know in case any further assistance is required for this case.

Regards,
Svetlin
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
EGrop
Top achievements
Rank 1
answered on 15 May 2019, 10:52 AM
Thanks for the answer. I am trying to implement the function with this approach.
0
Svet
Telerik team
answered on 17 May 2019, 06:09 AM
Hi,

Let us know in case any further assistance is required for this case.

Regards,
Svetlin
Progress Telerik
Get quickly onboarded and successful with your Telerik and Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
EGrop
Top achievements
Rank 1
Answers by
Svet
Telerik team
EGrop
Top achievements
Rank 1
Share this question
or