From aa32661261f8f9cf2a179a63c71cd4af80b53468 Mon Sep 17 00:00:00 2001 From: Timothy Barry Date: Fri, 13 Oct 2023 15:43:26 -0400 Subject: [PATCH] feat: Allow totalItems prop --- src/components/Table/UncontrolledTable.js | 4 +++- src/components/Table/UncontrolledTable.spec.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/Table/UncontrolledTable.js b/src/components/Table/UncontrolledTable.js index f985afd11..4da9bea98 100644 --- a/src/components/Table/UncontrolledTable.js +++ b/src/components/Table/UncontrolledTable.js @@ -19,6 +19,7 @@ export default class UncontrolledTable extends React.Component { column: PropTypes.string, ascending: PropTypes.bool, }), + totalItems: PropTypes.number, onSelect: PropTypes.func, onSort: PropTypes.func, onVisibleRowsChange: PropTypes.func, @@ -207,6 +208,7 @@ export default class UncontrolledTable extends React.Component { rows, selectable, sort, + totalItems, onSelect, onExpand, onSort, @@ -263,7 +265,7 @@ export default class UncontrolledTable extends React.Component { currentPage={page + 1} onClick={(pg) => this.setPage(pg - 1)} perPage={pageSize} - totalItems={rows.length} + totalItems={totalItems || rows.length} /> )} diff --git a/src/components/Table/UncontrolledTable.spec.js b/src/components/Table/UncontrolledTable.spec.js index 1ddb7a826..d920f521b 100644 --- a/src/components/Table/UncontrolledTable.spec.js +++ b/src/components/Table/UncontrolledTable.spec.js @@ -365,6 +365,22 @@ describe('', () => { assert.strictEqual(paginator.prop('currentPage'), 2); }); + it('should prefer totalItems prop for paginator, but default to rows.length', () => { + const columns = [{ header: 'Name', cell: (row) => row }]; + const rows = ['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot', 'Golf', 'Hotel']; + const wrapper = shallow( + + ); + let paginator = wrapper.find(Paginator); + + assert.strictEqual(paginator.prop('totalItems'), rows.length); + + wrapper.setProps({ totalItems: 10 }); + paginator = wrapper.find(Paginator); + + assert.strictEqual(paginator.prop('totalItems'), 10); + }); + it('should show correct rows on sort change', () => { const columns = [{ header: 'Name', key: 'name', cell: (row) => row }]; const rows = [{ name: 'Alpha' }, { name: 'Bravo' }, { name: 'Charlie' }];