如何在 agGrid detailGridOptions 中缩小 space

How to shrink space in agGrid detailGridOptions

我的 agGrid 下拉列表中有大量 space 由 detailGridOptions 呈现。 99% 的应用程序在下拉列表中只有一行。其他 1% 可能有 2 行。如何缩小下拉列表中的 space。 agGrid angular9

less- 我已经能够缩小 table 行的高度,使用下面的代码接近“ag-root-wrapper-body”的结尾和下面

    #AllLeaseView {
        input[type='radio'] {
            display: none;
        }
    
        .sales-summary-chart {
            svg.ngx-charts {
                margin-left: -35px;
                margin-top: 35px;
            }
        }
    
        .kt-portlet__head-toolbar .btn-group .btn {
            cursor: pointer;
        }
    }
    .k-grid tbody td {
        white-space: nowrap;
        line-height: 18px;
        padding: 8px 12px;
        font-size: 12px;
        font-weight: 500;
        vertical-align: top;
    }
    
    .k-grid th.k-header,
    .k-grid-header {
        font-size: 14px;
        font-weight: 900;
        padding: 10px 24px;
    }
    
    .rag-red {
        background-color: #e74c3c;
        color: black;
    }
    .rag-green {
        background-color: #00bc8c;
    }
    .rag-amber {
        background-color: #f39c12;
        color: black;
    }
    
    .ag-header-cell-text {
        overflow: visible !important;
        text-overflow: unset !important;
        white-space: normal !important;
     }
     .ag-root-wrapper-body.ag-layout-normal{
        max-height: 100px !important;
     }
    
     .ag-details-row, .ag-row-position-absolute, .ag-full-width-row {
         max-height: 150px !important;
     }

html-这里没什么好说的

    <ag-grid-angular domLayout='autoHeight' class="ag-theme-balham-dark"
                                    [rowData]="leases" [columnDefs]="columnDefs" [frameworkComponents]="frameworkComponents"
                                    [gridOptions]="gridOptions" [animateRows]="true" [detailCellRendererParams]="detailCellRendererParams"
                                    [overlayLoadingTemplate]="overlayLoadingTemplate" [masterDetail]="true"   (firstDataRendered)="onFirstDataRendered($event)"
                                    [sideBar]="sideBar" (gridReady)="onGridReady($event)">
                                </ag-grid-angular>

    this.detailCellRendererParams = {
            detailGridOptions: {
                columnDefs: [
                    {
                        field: 'tenantType',
                        headerName: ' Tenant Type',
                        cellRenderer(params) {
                            const tenantType = params.data.tenantType;
                            if (tenantType) {
                                return tenantType;
                            } else {
                                return;
                            }
                        },
                    },
                    { field: 'leaseTenantImprovements', headerName: 'TI (PSF)' },
                    { field: 'leaseFreeRentMonths', headerName: 'Free Rent Months' },
                    {
                        field: 'rentCommencementDate',
                        headerName: 'Commencement Date',
                        cellRenderer(params) {
                            return params.data.rentCommencementDate.format('MM/DD/YY');
                        },
                    },
                    { field: 'lessor' },
                    { field: 'guarantor' },
                    { field: 'renewalOptions' },
                    { field: 'purchaseOptions' },
                    { field: 'terminationClause' },
                    {
                        field: 'verifications',
                        headerName: ' Verification Date',
                        cellRenderer(params) {
                            return params.data.verifications[0].verificationDate.format('MM/DD/YY');
                        },
                    },
                    {
                        field: 'verifications',
                        headerName: 'Verified By',
                        cellRenderer(params) {
                            const verifiedByUserDto = _.find(this.users, {
                                id: params.data.verifications[0].verifiedByUserId,
                            });
                            if (verifiedByUserDto) {
                                return verifiedByUserDto.name;
                            } else {
                                return;
                            }
                        },
                    },
                ],......

您不应该为此要求任何花哨的 css 处理。 Ag-grid 文档有一个很好的例子来涵盖相同的内容。基本上,您只想根据行数将特定高度专用于详细信息网格。解决这个问题的 2 种方法 -

  1. 在主网格选项中使用 detailRowHeight

    masterGridOptions.detailRowHeight = 200;

  2. 实施getRowHeight

在HTML

中添加getRowHeight
[getRowHeight]="getRowHeight"

定义 getRowHeight 这样的东西 -

this.getRowHeight = function(params) {
  if (params.node && params.node.detail) { // this ensures it only applies to detail grid
    var offset = 80;
    var allDetailRowHeight =
      params.data.detailGrid.length *
      params.api.getSizesForCurrentTheme().rowHeight; //replace detailGrid with your detail grid rowdata property
    var gridSizes = params.api.getSizesForCurrentTheme();
    return allDetailRowHeight + gridSizes.headerHeight + offset;
  }
};

从文档

中查看这个example