Skip to content

Commit

Permalink
feat: Allow totalItems prop
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarry16 committed Oct 13, 2023
1 parent f156117 commit aa32661
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/Table/UncontrolledTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -207,6 +208,7 @@ export default class UncontrolledTable extends React.Component {
rows,
selectable,
sort,
totalItems,
onSelect,
onExpand,
onSort,
Expand Down Expand Up @@ -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}
/>
</>
)}
Expand Down
16 changes: 16 additions & 0 deletions src/components/Table/UncontrolledTable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,22 @@ describe('<UncontrolledTable />', () => {
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(
<UncontrolledTable columns={columns} rows={rows} paginated pageSize={4} />
);
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' }];
Expand Down

0 comments on commit aa32661

Please sign in to comment.