Skip to content

Commit

Permalink
Merge pull request #14 from lowdefy/fix-update-versions
Browse files Browse the repository at this point in the history
feat: Add sizeColumnsToFit and autoSize methods, closes #7
  • Loading branch information
Gervwyk authored Apr 7, 2022
2 parents 5ab39fd + f46c961 commit 4a76c89
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ The block types are hosted at:
### Methods

- `exportDataAsCsv`: When called, table data will be downloaded in csv format.
- `sizeColumnsToFit`: When called, size table column widths to fit all columns to table width.
- `autoSize`: When called, auto size columns. The following can be passed as the first argument of `args`.
- `skipHeader: boolean`: Do not consider header content width when auto-sizing columns.
- `columnIds: string[]`: List of `colId`s for which to calculate auto-size when called.

### AgGridAlpine Example

Expand Down
10 changes: 10 additions & 0 deletions src/AgGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ class AgGrid extends React.Component {
this.props.methods.registerMethod('exportDataAsCsv', (args) =>
this.gridApi.exportDataAsCsv(args)
);
this.props.methods.registerMethod('sizeColumnsToFit', () => this.gridApi.sizeColumnsToFit());
this.props.methods.registerMethod('autoSize', ({ skipHeader, colIds }) => {
const allColumnIds = colIds || [];
if (!colIds) {
this.gridColumnApi.getAllColumns().forEach((column) => {
allColumnIds.push(column.getId());
});
}
this.gridColumnApi.autoSizeColumns(allColumnIds, skipHeader);
});
}

onRowClick(event) {
Expand Down
10 changes: 10 additions & 0 deletions src/AgGridInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ class AgGridInput extends React.Component {
this.props.methods.registerMethod('exportDataAsCsv', (args) =>
this.gridApi.exportDataAsCsv(args)
);
this.props.methods.registerMethod('sizeColumnsToFit', () => this.gridApi.sizeColumnsToFit());
this.props.methods.registerMethod('autoSize', ({ skipHeader, colIds }) => {
const allColumnIds = colIds || [];
if (!colIds) {
this.gridColumnApi.getAllColumns().forEach((column) => {
allColumnIds.push(column.getId());
});
}
this.gridColumnApi.autoSizeColumns(allColumnIds, skipHeader);
});
}

onRowClick(event) {
Expand Down

0 comments on commit 4a76c89

Please sign in to comment.