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

[Solved] How can i fixed grid height?

2 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tawit
Top achievements
Rank 1
Tawit asked on 26 Nov 2011, 09:35 AM

I use this code ...

<%Html.Telerik().Grid<CDS.TMS.UI.Web.Areas.Security.Models.VRoleModel>()
  .Name("gridRole")
  .EnableCustomBinding(true)
  .DataKeys(keys => {keys.Add(m => m.RoleId);})
  .Columns(columns =>
  {
   ...
  })
  .Resizable(resizing => resizing.Columns(true))
  .DataBinding(databinding => { databinding.Ajax().Select("UserRole", "User", new { userId = Model.UserId }); })
  .ClientEvents(clientEvents => {clientEvents.OnDataBound("onDataBound");})
  .Scrollable(c => c.Enabled(true))
  .Selectable()
  .Footer(false)
  .Render();
 %>
 
 The default grid height is 200px, but I want to more or less, how can I set it?
 I want to fixed grid height is 300px.

2 Answers, 1 is accepted

Sort by
0
Linas
Top achievements
Rank 1
answered on 26 Nov 2011, 10:07 AM
.Scrollable(c => c.Enabled(true).Height(300))
0
Gennady
Top achievements
Rank 1
answered on 30 Nov 2011, 10:15 PM
I need the grid height to work well on different resolutions like 1024x768 and 1600x1200. I also want to always display the pager at the bottom.

Say I set the pager pageSize to 20. In my case when resolution is 1024x768 it can only show 8 items. So when I implemented your suggestion of .Scrollable(c => c.Enabled(true).Height(300)) (I tried using %) it makes it it possible to see remaining items but not until you scroll all the way down do you see the pager control which isn't what I'm going for.

This is obviously not uncommon for folks wanting out of the grid. Ideally, the grid should have intelligence and adjust the height and pageSize dynamically.

I looked at modifying the height and pageSize myself client side, but there doesn't appear to be a pageSize client api that it reacts to and then how to force the grid to update to the new pageSize value.

Anyone know how to solve this? Does Telerik have a solution for this?

I found someone trying to do the same with this code but doesn't seem to work (http://stackoverflow.com/questions/5433618/automatic-paging-based-on-content-area-resolution-telerik-grid)
function onLoad(e)
   
{
       
//Gets the height of the Window. ($(window).height())
       
//Subracts the height of any menus/headers/footers (in this case 275)
       
//Then divide by our "magic number" which you will need to tinker with
       
//to determine how the grid looks in different browsers. (in this case 28)

       
var height = Math.floor(($(window).height()-275)/28);
       
var grid = $("#YourGrid").data("tGrid");
       grid
.pageSize = height;
   
}  

Formula :

$(window).height() - [Occupied Space] / [Magic Number]

[Occupied Space] - Total CSS Height of all objects above the Grid.

[Magic Number]   - You will have to play with this one and try it out on
                   different browsers
until you get the expected results.
Tags
Grid
Asked by
Tawit
Top achievements
Rank 1
Answers by
Linas
Top achievements
Rank 1
Gennady
Top achievements
Rank 1
Share this question
or