Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for including hidden columns when autosizing #3424

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

### 🎁 New Features

* New `GridAutosizeOptions.includeHiddenColumns` config controls whether hidden columns should
also be included during the autosize process. Default of `false`. Useful when applications
provide quick toggles between different column sets and would prefer to take the up-front cost of
autosizing rather than doing it after the user loads a column set.
* New `DashModel.refreshContextModel` allows apps to programmatically refresh all widgets within
a `DashCanvas` or `DashContainer`.

Expand Down
6 changes: 6 additions & 0 deletions cmp/grid/GridAutosizeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export interface GridAutosizeOptions {
*/
includeCollapsedChildren?: boolean;

/**
* True to also autosize hidden columns.
* Note that setting this to true can have performance impacts for grids with many columns hidden by default.
*/
includeHiddenColumns?: boolean;

/**
* Columns ids to autosize, or a function for testing if the given column should be
* autosized. Typically used when calling autosizeAsync() manually. To generally exclude
Expand Down
25 changes: 21 additions & 4 deletions cmp/grid/GridModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,79 +870,95 @@ export class GridModel extends HoistModel {
get isReady(): boolean {
return this.agGridModel.isReady;
}

get agApi() {
return this.agGridModel.agApi;
}

get agColumnApi() {
return this.agGridModel.agColumnApi;
}

get sizingMode(): SizingMode {
return this.agGridModel.sizingMode;
}

set sizingMode(v: SizingMode) {
this.agGridModel.sizingMode = v;
}

setSizingMode(v: SizingMode) {
this.agGridModel.sizingMode = v;
}

get showHover(): boolean {
return this.agGridModel.showHover;
}

set showHover(v: boolean) {
this.agGridModel.showHover = v;
}

setShowHover(v: boolean) {
this.agGridModel.showHover = v;
}

get rowBorders(): boolean {
return this.agGridModel.rowBorders;
}

set rowBorders(v: boolean) {
this.agGridModel.rowBorders = v;
}

setRowBorders(v: boolean) {
this.agGridModel.rowBorders = v;
}

get stripeRows(): boolean {
return this.agGridModel.stripeRows;
}

set stripeRows(v: boolean) {
this.agGridModel.stripeRows = v;
}

setStripeRows(v: boolean) {
this.agGridModel.stripeRows = v;
}

get cellBorders(): boolean {
return this.agGridModel.cellBorders;
}

set cellBorders(v: boolean) {
this.agGridModel.cellBorders = v;
}

setCellBorders(v: boolean) {
this.agGridModel.cellBorders = v;
}

get showCellFocus(): boolean {
return this.agGridModel.showCellFocus;
}

set showCellFocus(v: boolean) {
this.agGridModel.showCellFocus = v;
}

setShowCellFocus(v: boolean) {
this.agGridModel.showCellFocus = v;
}

get hideHeaders(): boolean {
return this.agGridModel.hideHeaders;
}

set hideHeaders(v: boolean) {
this.agGridModel.hideHeaders = v;
}

setHideHeaders(v: boolean) {
this.agGridModel.hideHeaders = v;
}
Expand Down Expand Up @@ -1263,10 +1279,11 @@ export class GridModel extends HoistModel {
/**
* Autosize columns to fit their contents.
*
* @param options - overrides of default autosize options to use for this action.
* This method will ignore columns with a flex value or with `autosizable: false`. Hidden
* columns are also ignored unless {@link GridAutosizeOptions.includeHiddenColumns} has been
* set to true.
*
* This method will ignore hidden columns, columns with a flex value, and columns with
* autosizable = false.
* @param options - optional overrides of this model's configured {@link autosizeOptions}.
*/
@logWithDebug
async autosizeAsync(options: GridAutosizeOptions = {}) {
Expand All @@ -1290,7 +1307,7 @@ export class GridModel extends HoistModel {
}

colIds = castArray(colIds).filter(id => {
if (!this.isColumnVisible(id)) return false;
if (!options.includeHiddenColumns && !this.isColumnVisible(id)) return false;
const col = this.getColumn(id);
return col && col.autosizable && !col.flex && includeColFn(col);
});
Expand Down