diff --git a/src/components/FiDataGrid.js b/src/components/FiDataGrid.js index cef7b661..9fb6d091 100644 --- a/src/components/FiDataGrid.js +++ b/src/components/FiDataGrid.js @@ -73,7 +73,9 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, useEffect(() => { if (doLoad !== undefined && Object.keys(doLoad).length>0 ){ - if(applySearch!=undefined){ + if (disablePagingOnGazetteIssue && hasGazetteIssueFilter(doLoad.params)) { + setPage(0); + } else if(applySearch!=undefined){ if (Object.keys(getSearchCriteria(window.location.pathname)).length>0){ const localStorageSearchCriteria = getSearchCriteria(window.location.pathname) // console.log(localStorageSearchCriteria) @@ -117,6 +119,7 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, if (!pagination || (disablePagingOnGazetteIssue && hasGazetteIssueFilter(params))) { delete params.start; delete params.limit; + setPage(0); } else { params.start = 0; params.limit = pageSize; @@ -130,8 +133,9 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, } }; - const ignorePaging = !pagination || (disablePagingOnGazetteIssue && hasGazetteIssueFilter(_doLoad?.params)); - const effectivePagination = pagination && !ignorePaging; + const loadAllOnGazetteIssue = disablePagingOnGazetteIssue && hasGazetteIssueFilter(_doLoad?.params); + const ignorePagingParams = !pagination || loadAllOnGazetteIssue; + const showPaginationBar = pagination; useEffect(() => { getDataList(); @@ -216,7 +220,7 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, if (_doLoad.params == undefined) return; if (_doLoad.params.searchCriteria !== undefined) return; if (_doLoad.params == null) _doLoad.params = {}; - if (!pagination || (disablePagingOnGazetteIssue && hasGazetteIssueFilter(_doLoad.params))) { + if (ignorePagingParams) { delete _doLoad.params.start; delete _doLoad.params.limit; } else { @@ -314,13 +318,13 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, disableColumnMenu shrinkWrap rowModesModel={_rowModesModel} - pageSizeOptions={effectivePagination ? _pageSizeOptions : []} + pageSizeOptions={showPaginationBar ? _pageSizeOptions : []} editMode={_editMode} autoHeight={effectiveAutoHeight} hideFooterSelectedRowCount={myHideFooterSelectedRowCount} filterModel={{ items: _filterItems }} loading={loading} - paginationMode={effectivePagination ? "server" : undefined} + paginationMode={showPaginationBar ? "server" : undefined} sortingMode={serverSorting ? "server" : undefined} sortModel={serverSorting ? sortModel : undefined} onSortModelChange={serverSorting ? handleSortModelChange : undefined} @@ -334,8 +338,8 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, '& .MuiDataGrid-overlay': { backgroundColor: 'rgba(255, 255, 255, 0.55)', }, - // 👇 completely hide the footer when pagination is off - ...(!effectivePagination && { + // Hide the footer only when pagination is disabled for the grid + ...(!showPaginationBar && { '& .MuiDataGrid-footerContainer': { display: 'none', }, @@ -343,22 +347,27 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, }} components={{ NoRowsOverlay: CustomNoRowsOverlay, - ...(effectivePagination + ...(showPaginationBar ? { - Pagination: () => ( + Pagination: () => { + const total = rowCount || 0; + const pagerPage = loadAllOnGazetteIssue ? 0 : page; + const pagerPageSize = loadAllOnGazetteIssue ? Math.max(total, 1) : pageSize; + return ( { - const total = rowCount || 0; if (!_rows?.length || total === 0) { return `0-0 ${intl.formatMessage({ id: "of" })} ${total}`; } - const from = page * pageSize + 1; - const to = Math.min(page * pageSize + _rows.length, total); + const from = loadAllOnGazetteIssue ? 1 : page * pageSize + 1; + const to = loadAllOnGazetteIssue + ? _rows.length + : Math.min(page * pageSize + _rows.length, total); return `${from}-${to} ${intl.formatMessage({ id: "of" })} ${total}`; }} labelRowsPerPage={intl.formatMessage({ id: "rowsPerPage" }) + ":"} @@ -371,10 +380,11 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, } return ''; }} - onPageChange={handleChangePage} - onRowsPerPageChange={handleChangePageSize} + onPageChange={loadAllOnGazetteIssue ? () => {} : handleChangePage} + onRowsPerPageChange={loadAllOnGazetteIssue ? () => {} : handleChangePageSize} /> - ), + ); + }, } : {}), }}