I know there is an easy way to set fixed height of a Kendo UI grid through their API but for our specific needs, I need to make the grid expand in full height of its wrapper.
With the following markup structure, I set .wrapper
to height:600px
and I tried to give .k-grid-content
height:100%
but it doesn't expand.
#grid
expands to 100% with height:100%
but I need the inside contents to expand as well. How do I achieve that?
Here is the demo JS BIN
<div class="wrapper">
<div id="grid">
<div class="k-grid-header"></div>
<div class="k-grid-content"></div>
<div class="k-grid-pager"></div>
</div>
</div>
If you don't mind people with IE8 this is the way to go:
Just add any of the
k-grid-stretch-height-AXZ
classes along sidek-grid
and play with pixel numbers.I created another solution that works when your html is different in the sense that its not just the grid alone but other content above it. The JSFiddle is located here.
HTML
CSS
JS
The key in my solution is the modified resizeGrid function. What happens without this modification is if the user scrolls far enough upwards the bottom pager gets lost! By checking to make sure the newHeight-diff is greater than 0 it prevents this error.
Second calcHeightsOfParentChildren when passed the element of the grid in question will calculate all the other heights except its own to help calculate the correct difference to place the pager control and grid so that it truly takes up 100% and retains its 100% ratio.
You have to do two things.
$('.k-grid table')
height on page resize$('.k-grid table')
height on dataBound method of gridPlease see it in jsBin http://jsbin.com/xorawuya/1/edit
And also here
The
150
which I am subtracting is the height of window minus height of the grid header/footer. This could be different in your website layout. Adjust it accordingly.According to one of Kendo's tech support team; Dimo Dimov. You should set the height of one container, and everything inside should be set to 100% (including the grid). Then you manually adjust the content height on document ready and window resize.
See here for his example:
http://jsfiddle.net/dimodi/SDFsz/
See here for yours updated with a js function to set the height of the wrapper to the window height.
http://jsbin.com/yumexugo/1/edit
Essentially the content is resized with:
and the wrapper is sized with (you may need to modify this to suit your layout):
Document ready and window resize both call:
Relevant css: