Skip to content

Commit e33c227

Browse files
authored
feat(AnalyticalTable): introduce additionalEmptyRowsCount prop (#5412)
Fixes #5278
1 parent f9b7b0e commit e33c227

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

packages/main/src/components/AnalyticalTable/AnalyticalTable.cy.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
AnalyticalTableScaleWidthMode,
99
AnalyticalTableSelectionBehavior,
1010
AnalyticalTableSubComponentsBehavior,
11-
AnalyticalTableVisibleRowCountMode,
1211
Button,
1312
Input
1413
} from '../..';
@@ -1086,7 +1085,15 @@ describe('AnalyticalTable', () => {
10861085
>
10871086
Data 100
10881087
</Button>
1088+
<Button
1089+
onClick={() => {
1090+
setData(data.slice(0, 10));
1091+
}}
1092+
>
1093+
Data 10
1094+
</Button>
10891095
<AnalyticalTable
1096+
{...props}
10901097
ref={tableRef}
10911098
data-testid="at"
10921099
data={internalData}
@@ -1135,6 +1142,15 @@ describe('AnalyticalTable', () => {
11351142
cy.findByText('Name91').should('be.visible');
11361143
cy.findByText('Rows: 150').should('be.visible');
11371144
cy.get('@more').should('have.been.calledThrice');
1145+
1146+
//additionalEmptyRowsCount
1147+
cy.mount(<TestComp onLoadMore={onLoadMore} additionalEmptyRowsCount={1} />);
1148+
cy.get('[data-empty-row="true"]').should('not.exist');
1149+
cy.findByText('Data 10').click();
1150+
cy.findByText('Rows: 10').should('be.visible');
1151+
cy.get('[data-empty-row="true"]').should('exist').should('not.be.visible');
1152+
cy.findByTestId('scrollInput').typeIntoUi5Input('11{enter}', { force: true });
1153+
cy.findByText('Rows: 60').should('be.visible');
11381154
});
11391155

11401156
it('InfiniteScroll: Tree', () => {
@@ -2660,6 +2676,17 @@ describe('AnalyticalTable', () => {
26602676
cy.findByText('12').should('not.be.visible');
26612677
});
26622678

2679+
it('additionalEmptyRowsCount', () => {
2680+
cy.mount(<AnalyticalTable data={data} columns={columns} minRows={4} />);
2681+
cy.get('[data-empty-row]').should('not.exist');
2682+
cy.mount(<AnalyticalTable data={data} columns={columns} minRows={4} additionalEmptyRowsCount={1} />);
2683+
cy.get('[data-empty-row]').should('exist').and('not.be.visible');
2684+
cy.mount(<AnalyticalTable data={data} columns={columns} minRows={4} additionalEmptyRowsCount={5} />);
2685+
cy.get('[data-empty-row]').should('exist').and('have.length', 5).and('not.be.visible');
2686+
cy.get('[data-component-name="AnalyticalTableBody"]').scrollTo('bottom');
2687+
cy.get('[data-empty-row]').should('exist').and('have.length', 5).and('be.visible');
2688+
});
2689+
26632690
cypressPassThroughTestsFactory(AnalyticalTable, { data, columns });
26642691
});
26652692

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
151151
onTableScroll,
152152
LoadingComponent,
153153
NoDataComponent,
154+
additionalEmptyRowsCount = 0,
154155
alwaysShowSubComponent: _omit,
155156
...rest
156157
} = props;
@@ -748,13 +749,15 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
748749
classes={classes}
749750
prepareRow={prepareRow}
750751
rows={rows}
751-
itemCount={Math.max(
752-
minRows,
753-
rows.length,
754-
visibleRowCountMode === AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows
755-
? internalVisibleRowCount
756-
: 0
757-
)}
752+
itemCount={
753+
Math.max(
754+
minRows,
755+
rows.length,
756+
visibleRowCountMode === AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows
757+
? internalVisibleRowCount
758+
: 0
759+
) + (!tableState.isScrollable ? additionalEmptyRowsCount : 0)
760+
}
758761
scrollToRef={scrollToRef}
759762
isTreeTable={isTreeTable}
760763
internalRowHeight={internalRowHeight}
@@ -779,7 +782,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
779782
</VirtualTableBodyContainer>
780783
)}
781784
</div>
782-
{(tableState.isScrollable === undefined || tableState.isScrollable) && (
785+
{(additionalEmptyRowsCount || tableState.isScrollable === undefined || tableState.isScrollable) && (
783786
<VerticalScrollbar
784787
tableBodyHeight={tableBodyHeight}
785788
internalRowHeight={internalHeaderRowHeight}

packages/main/src/components/AnalyticalTable/types/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,16 @@ export interface AnalyticalTablePropTypes extends Omit<CommonProps, 'title'> {
359359
| AnalyticalTableVisibleRowCountMode
360360
| keyof typeof AnalyticalTableVisibleRowCountMode
361361
| TableVisibleRowCountMode;
362-
362+
/**
363+
* Specifies the number of additional empty rows added to the bottom of a table that is normally __non__ scrollable.
364+
* Use this prop if you want to ensure that the table is scrollable.
365+
*
366+
* __Note:__ It's recommended to use this prop only if `infiniteScroll` is applied and where assessing scrollability is not possible across various resolutions or datasets.
367+
* E.g., when using `visibleRowCountMode` with values `"Auto"` or `"AutoWithEmptyRows"`.
368+
*
369+
* __Note:__ This prop has no effect if the table is already scrollable without additional empty rows.
370+
*/
371+
additionalEmptyRowsCount?: number;
363372
/**
364373
* The number of rows visible without going into overflow.
365374
*

0 commit comments

Comments
 (0)