Skip to content

Commit

Permalink
[WIP] hello darkness my old friend...
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Oct 28, 2021
1 parent 8cbe865 commit 2655093
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions src-docs/src/views/datagrid/datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ export default () => {
onChangePage: onChangePage,
}}
onColumnResize={onColumnResize.current}
rowHeightsOptions={{ defaultHeight: { lineCount: 10 } }}
/>
</DataContext.Provider>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/datagrid/body/data_grid_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ export class EuiDataGridCell extends Component<
rowHeightUtils?.shouldCacheCellHeight(rowIndex, rowHeightsOptions)
) {
const { columnId, visibleRowIndex } = this.props;
const rowHeight = this.cellContentsRef.offsetHeight;

rowHeightUtils.setRowHeight(
rowIndex,
columnId,
rowHeight,
visibleRowIndex
this.cellContentsRef,
visibleRowIndex,
rowHeightsOptions
);
}
};
Expand Down
34 changes: 26 additions & 8 deletions src/components/datagrid/row_height_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,38 @@ export class RowHeightUtils {
setRowHeight(
rowIndex: number,
colId: string,
height: number = DEFAULT_ROW_HEIGHT,
visibleRowIndex: number
cellRef: HTMLElement,
visibleRowIndex: number,
rowHeightsOptions?: EuiDataGridRowHeightsOptions
) {
const heightOption = this.getRowHeightOption(rowIndex, rowHeightsOptions);
const cellHeight = cellRef.offsetHeight || DEFAULT_ROW_HEIGHT;
let updatedHeight;

if (this.isLineCount(heightOption)) {
const { lineCount } = heightOption as { lineCount: number };

const styles = window.getComputedStyle(cellRef, null);
const lineHeight = parseInt(styles.lineHeight, 10) || 24;

updatedHeight = Math.ceil(
lineCount * lineHeight +
this.styles.paddingTop +
this.styles.paddingBottom
);
} else {
updatedHeight = Math.ceil(
cellHeight + this.styles.paddingTop + this.styles.paddingBottom
);
}

const rowHeights =
this.heightsCache.get(rowIndex) || new Map<string, number>();
const adaptedHeight = Math.ceil(
height + this.styles.paddingTop + this.styles.paddingBottom
);

if (rowHeights.get(colId) === adaptedHeight) {
if (rowHeights.get(colId) === updatedHeight) {
return;
}

rowHeights.set(colId, adaptedHeight);
rowHeights.set(colId, updatedHeight);
this.heightsCache.set(rowIndex, rowHeights);
this.resetRow(visibleRowIndex);
}
Expand Down

0 comments on commit 2655093

Please sign in to comment.