How to set a min height on a jqgrid which needs to have height: 'auto' so it can expand as needed

47 Views Asked by At

In a .net6 web application, I have a jqgrid that currently height: 'auto'.

Some of the columns in the grid have a dropdown. The problem is that when there is only one row in the grid then values in the drop downs when expanded are not visible.

I would like the height of the grid to be set to a minimum of records even when there is one. If there are more than 3 records then the height should increase. The max number of records per page of the grid is 20.

The only challenge I am facing is setting the height to max(3,number of records).

I tried the following but it didnt work:

<text>
  $('#@item.CurrencyName').jqGrid({
    url: '[email protected]&[email protected]&[email protected]',
    jsonReader: {
      root: 'rows',
      page: 'page',
      total: 'total',
      records: 'records',
      repeatitems: false,
      cell: 'cell',
      id: 'id',
      userdata: 'userdata'
    },
    datatype: 'json',
    sortname: 'Account',
    gridview: true,
    altRows: true,
    autowidth: true,
    height: function () {
    // Calculate the minimum height based on the minimum row count and row height
    var minGridHeight = 3 * $(this).jqGrid('getGridParam', 'rowNum');
    var currentGridHeight = $(this).jqGrid('getGridParam', 'records');
    return Math.max(minGridHeight, currentGridHeight);,
    sortable: true,
    loadonce: false,
    pager: '#[email protected]',
    pagerpos: 'right',
    recordpos: 'left',
    viewrecords: true,
    rowNum: 25,
    ....etc...

I tried also with the following but it doesnt seem that any value is being returned as a height :

height: function () {
        // Calculate the minimum height based on the minimum row count and row height
             If($(this).getGridParam("reccount") > 3)
            {return 'auto';} else {return 300;}
        },

Thank you

0

There are 0 best solutions below