Monday 28 November 2022

AG-Grid master detail dynamically set master panel height based on detail sizes, and detail grid auto height to fit entire panel

 Detial Grid set autoHeight to fit entire panel :

https://www.ag-grid.com/javascript-data-grid/master-detail-height/


detail grid Option:

        gridOptions.rowHeight = this.ROW_HEIGHT;

        gridOptions.gridAutoHeight = true;


Master grid dynamic detail grid panel height

https://www.ag-grid.com/angular-data-grid/row-height/

master grid Option:


        gridOptions.getRowHeight = (params) => {
            if (params.node && params.node.detail) {
                // calculated in detail grid
                return 0;
            }

            return 73;

        };

detail grid 
    agInit(params01: any): void {
        this.masterParams = params01;
        this.masterRowIndex = params01.rowIndex;
        this.rowData = params01.data.sns;
    }
            

this.gridDataRendered.subscribe((next: boolean) => {
              // Update parent's row height
                setTimeout(() => {
                    this.masterParams.node.setRowHeight(
                        this.calculateParentRowHeight()
                    );
                    this.masterParams.api.onRowHeightChanged();
                }, 0);


                // Listen on the filterChanged event
                this.params.api.addEventListener(
                    "filterChanged",
                    ($event: FilterChangedEvent) => {
                        // Update parent's row height
                        setTimeout(() => {
                            this.masterParams.node.setRowHeight(
                                this.calculateParentRowHeight()
                            );
                            this.masterParams.api.onRowHeightChanged();
                        }, 0);
                    }
                );

..............................

}


    private calculateParentRowHeight(): number {
        // NOTE: must have this to display properly
        const offset =
            this.masterParams.api.getSizesForCurrentTheme().headerHeight;

        const rowHeight = this.ROW_HEIGHT;

        let numRows = this.params.api.getDisplayedRowCount();

        return rowHeight * numRows + offset;
    }

No comments:

Post a Comment