Skip to content

Commit

Permalink
Merge pull request #281 from EMCECS/feature-OBSDEF-46383-show-paginat…
Browse files Browse the repository at this point in the history
…ion-options-for-at-least-one-record

[OBSDEF-46383] Show pagination options if at least 1 record is present
  • Loading branch information
netraja-chavan authored Apr 22, 2024
2 parents 65ac1c4 + fca1ad6 commit b2ec09d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dellstorage/clarity-react",
"version": "1.2.10",
"version": "1.2.11",
"description": "React components for Clarity UI",
"license": "Apache-2.0",
"private": false,
Expand Down
22 changes: 12 additions & 10 deletions src/datagrid/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,17 @@ export class DataGrid extends React.PureComponent<DataGridProps, DataGridState>

// Function to handle CustomPageSize change in input box
private handleCustomPageSizeChange = () => {
const {maxCustomPageSize} = this.state.pagination!;
const {maxCustomPageSize, totalItems} = this.state.pagination!;
const pageSize = this.customPageSizeRef.current && parseInt(this.customPageSizeRef.current.value);

if (pageSize && maxCustomPageSize && pageSize <= maxCustomPageSize) {
this.getPage(this.state.pagination!.currentPage, pageSize);
} else if (pageSize && maxCustomPageSize && pageSize > maxCustomPageSize) {
if (this.customPageSizeRef.current) {
this.customPageSizeRef.current.value = maxCustomPageSize.toString();
if (pageSize && maxCustomPageSize) {
if (pageSize <= maxCustomPageSize) {
this.getPage(this.state.pagination!.currentPage, pageSize);
}
//If page size selected by user is greater than maximum limit for custom page size
else if (pageSize > maxCustomPageSize && this.customPageSizeRef.current) {
this.customPageSizeRef.current.value =
totalItems < maxCustomPageSize ? totalItems.toString() : maxCustomPageSize.toString();
this.getPage(DEFAULT_CURRENT_PAGE_NUMBER, parseInt(this.customPageSizeRef.current.value));
}
}
Expand Down Expand Up @@ -1619,7 +1622,7 @@ export class DataGrid extends React.PureComponent<DataGridProps, DataGridState>
const {className, style, compactFooter} = this.props.pagination!;
const {itemText = DEFAULT_ITEM_TEXT} = this.props;
const showCompactFooter: boolean = compactFooter || this.isDetailPaneOpen();
let {totalItems, firstItem, lastItem, pageSize, pageSizes = DEFAULT_PAGE_SIZES} = this.state.pagination!;
let {totalItems, firstItem, lastItem, pageSizes = DEFAULT_PAGE_SIZES} = this.state.pagination!;
if (totalItems === 0) {
firstItem = lastItem = 0;
}
Expand All @@ -1633,8 +1636,7 @@ export class DataGrid extends React.PureComponent<DataGridProps, DataGridState>
style={style}
className={classNames([ClassNames.DATAGRID_PAGINATION, className])}
>
{!showCompactFooter && pageSizes && totalItems >= pageSize && this.buildPageSizesSelect()}

{!showCompactFooter && pageSizes && totalItems > 0 && this.buildPageSizesSelect()}
{showCompactFooter ? (
<div className={ClassNames.DATAGRID_NG_STAR_INSERTED} style={Styles.PAGINATION_DESCRIPTION_COMPACT}>
{paginationLabel}
Expand Down Expand Up @@ -1690,7 +1692,7 @@ export class DataGrid extends React.PureComponent<DataGridProps, DataGridState>
let renderPaginationFooter = false;
if (pagination) {
const {totalItems, pageSize} = pagination;
if (totalItems && pageSize && totalItems >= pageSize) {
if (totalItems && pageSize && totalItems > 0) {
renderPaginationFooter = true;
}
}
Expand Down

0 comments on commit b2ec09d

Please sign in to comment.