tonytomov / jqGrid

jQuery grid plugin

Home Page:www.trirand.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use `height:auto` with max-height to avoid infinite growth

systemsolutionweb opened this issue · comments

Is there a way to achieve auto height but with a limit to prevent the grid from growing too large?

I found maxHeight property of others forks, has this plugins a similar property for that?
https://github.com/free-jqgrid/jqGrid/blob/c97869acd736030242469337343106f6cb56f731/js/grid.base.js#L6141-L6143

if (p.maxHeight) {
    $(grid.bDiv).css("max-height", p.maxHeight + (isNaN(p.maxHeight) ? "" : "px"));
}

thanks in advance, this plugin is amazing

This is the original plugin. We have such option via method - it is named maxGridHeight. It is documented in method list and you can find it here.

Best Regards

Thanks for your reply

We have such option via method - it is named maxGridHeight

Yes but that method doesn't work when the jgrid starts with data and datatype:'local', that is why i'm searching for a property config

Example: Maybe is a bug
https://jsfiddle.net/anz5u2r7/3/
On this example i did add a delRowData after 3 seconds for the resize
Also after that the width no fit with the scrollbar

Hello,
Thank you. This is a really bug.

Use it for now like this

$("#grid1").maxGridHeight('set',200).trigger("jqGridAfterGridComplete.setMaxHeght");

I will fix it ASAP.

$("#grid1").maxGridHeight('set',200).trigger("jqGridAfterGridComplete.setMaxHeght");

is setMaxHeght a typo?? maybe must be jqGridAfterGridComplete.setMaxHeight

$($t).off('jqGridAfterGridComplete.setMaxHeght');

Oh, was intencional or a mistake?

Yes it is a typo in the code, but it seems I will remove it.

I have fixed it. You can use it without to call jqGridAfterGridComplete.setMaxHeght, which is not needed,
Thanks

Have do more improvements on the method 2bf28a0

Thank you very much 👍

Hi @tonytomov

Also after that the width no fit with the scrollbar

After using maxGridHeight, data from last column is hidden by scrollbar, example: jsfiddle
image
(tested on actual dev master branch, resizeGrid doesn't work)

Is there a way to reload grid with a correct width?

Since the method only set the css max-height property without to do any future action you may need in your case to call setGridWidth with the current width + scrollOffset width. This can be done like this

var gridprm = $("#grid1").jqGrid('getGridParam'); // get all grid parameters
var neww = gridprm.width + gridprm.scrollOffset-2; // two pixel for the borders
$("#grid1").maxGridHeight('set',250).jqGrid('setGridWidth', neww, false);

Thanks, it works, at start at less
When window trigger resize/onorientationchange or change parent width and resizeGrid, it happends again on responsive:true,autowidth:true

image

If there a chance to add on setGridWidth or resizeGrid a validation for letting scrollOffset-2 always when max-height is setted

if( $($t.grid.bDiv).css("max-height") && ['100%','auto'].includes($t.p.height) )

Hello,

I will see what I can do

I have played with this and try to include the suggested code, but there is a problem in case the sum of height of the current grid view is smaller than the max-width

maxgridheight

As can be seen we need to do additional check if the current height is greater than the max one

I have updated the source. You will need just in initial loading set the new grid width. From this point resizeGrid will do the job.

It seems I have rewritre the maxGridHeight again. You do not need to do anything, just call it, and it will do the job again with resizeGrid.

Best Regards

Amazing, thanks