瀏覽代碼

CR023 - show record count in application and proof search with gazette issue

CR023
Jason Chuang 1 月之前
父節點
當前提交
b6091ac9d2
共有 1 個檔案被更改,包括 30 行新增20 行删除
  1. +30
    -20
      src/components/FiDataGrid.js

+ 30
- 20
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 (
<TablePagination
component="div"
count={rowCount || 0}
page={page}
rowsPerPage={pageSize}
rowsPerPageOptions={_pageSizeOptions}
count={total}
page={pagerPage}
rowsPerPage={pagerPageSize}
rowsPerPageOptions={loadAllOnGazetteIssue ? [] : _pageSizeOptions}
labelDisplayedRows={() => {
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}
/>
),
);
},
}
: {}),
}}


Loading…
取消
儲存