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

[EuiDataGrid] improve height calculation #5447

24 changes: 23 additions & 1 deletion src/components/datagrid/body/data_grid_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,33 @@ export const EuiDataGridBody: FunctionComponent<EuiDataGridBodyProps> = (
}
}, [getRowHeight]);

let knownHeight = 0;
let knownRowCount = 0;
for (let i = startRow; i < endRow; i++) {
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
const correctRowIndex = getCorrectRowIndex(i);
const rowHeightOption = rowHeightUtils.getRowHeightOption(
correctRowIndex,
rowHeightsOptions
);
if (rowHeightOption) {
knownRowCount++;
knownHeight += rowHeightUtils.getCalculatedHeight(
rowHeightOption,
defaultHeight, // minRowHeight,
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
correctRowIndex,
rowHeightUtils.isRowHeightOverride(correctRowIndex, rowHeightsOptions)
);
}
}

const rowCountToAffordFor = pagination
? pagination.pageSize
: visibleRowIndices.length;
const unconstrainedHeight =
defaultHeight * rowCountToAffordFor + headerRowHeight + footerRowHeight;
defaultHeight * (rowCountToAffordFor - knownRowCount) +
knownHeight +
headerRowHeight +
footerRowHeight;

// unable to determine this until the container's size is known anyway
const unconstrainedWidth = 0;
Expand Down
29 changes: 29 additions & 0 deletions src/components/datagrid/data_grid.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,35 @@ describe('EuiDataGrid', () => {
.should('have.lengthOf', 0);
});
});

describe('height calculation', async () => {
it('computes a new unconstrained height when switching to auto height', () => {
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
const renderCellValue: EuiDataGridProps['renderCellValue'] = ({
rowIndex,
columnId,
}) => (
<>
row {rowIndex}
<br />
column {columnId}
</>
);

mount(<EuiDataGrid {...baseProps} renderCellValue={renderCellValue} />);

getGridData();
cy.get('[data-test-subj=euiDataGridBody]')
.invoke('outerHeight')
.then((firstHeight) => {
cy.get('[data-test-subj=dataGridDisplaySelectorPopover]').click();
cy.get('[data-text="Auto fit"]').click();

cy.get('[data-test-subj=euiDataGridBody]')
.invoke('outerHeight')
.should('be.greaterThan', firstHeight);
});
});
});
});

function getGridData() {
Expand Down