tonytomov / jqGrid

jQuery grid plugin
www.trirand.com
2.84k stars 1.2k forks source link

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

Closed systemsolutionweb closed 2 years ago

systemsolutionweb commented 2 years ago

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

tonytomov commented 2 years ago

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

systemsolutionweb commented 2 years ago

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

tonytomov commented 2 years ago

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.

systemsolutionweb commented 2 years ago
$("#grid1").maxGridHeight('set',200).trigger("jqGridAfterGridComplete.setMaxHeght");

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

https://github.com/tonytomov/jqGrid/blob/e593e6013236ec8c6f977671bfe64395ccd571ca/js/grid.base.js#L6581

Oh, was intencional or a mistake?

tonytomov commented 2 years ago

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

tonytomov commented 2 years ago

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

tonytomov commented 2 years ago

Have do more improvements on the method https://github.com/tonytomov/jqGrid/commit/2bf28a0c56ac7ff90f825aee6ca44142f67878f0

systemsolutionweb commented 2 years ago

Thank you very much 👍

systemsolutionweb commented 2 years ago

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?

tonytomov commented 2 years ago

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);
systemsolutionweb commented 2 years ago

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) )
tonytomov commented 2 years ago

Hello,

I will see what I can do

tonytomov commented 2 years ago

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

tonytomov commented 2 years ago

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.

tonytomov commented 2 years ago

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

systemsolutionweb commented 2 years ago

Amazing, thanks