| @@ -14,7 +14,7 @@ import { getSearchCriteria, checkSearchCriteriaPath } from "auth/utils"; | |||||
| export function FiDataGrid({ rows, columns, sx, autoHeight = true, | export function FiDataGrid({ rows, columns, sx, autoHeight = true, | ||||
| hideFooterSelectedRowCount, rowModesModel, editMode, | hideFooterSelectedRowCount, rowModesModel, editMode, | ||||
| pageSizeOptions, filterItems, customPageSize, doLoad, applyGridOnReady, applySearch, | pageSizeOptions, filterItems, customPageSize, doLoad, applyGridOnReady, applySearch, | ||||
| tab, height, maxHeight, pagination = true, ...props }) { | |||||
| tab, height, maxHeight, pagination = true, serverSorting = false, ...props }) { | |||||
| const intl = useIntl(); | const intl = useIntl(); | ||||
| const [_rows, set_rows] = useState([]); | const [_rows, set_rows] = useState([]); | ||||
| const [_doLoad, set_doLoad] = useState({}); | const [_doLoad, set_doLoad] = useState({}); | ||||
| @@ -27,6 +27,7 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, | |||||
| const [page, setPage] = useState(0); | const [page, setPage] = useState(0); | ||||
| const [pageSize, setPageSize] = useState(10); | const [pageSize, setPageSize] = useState(10); | ||||
| const [sortModel, setSortModel] = useState([]); | |||||
| // const [_autoHeight, set_autoHeight] = useState(true); | // const [_autoHeight, set_autoHeight] = useState(true); | ||||
| const [myHideFooterSelectedRowCount, setMyHideFooterSelectedRowCount] = useState(true); | const [myHideFooterSelectedRowCount, setMyHideFooterSelectedRowCount] = useState(true); | ||||
| const [_sx, set_sx] = useState({ | const [_sx, set_sx] = useState({ | ||||
| @@ -78,11 +79,45 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, | |||||
| setPage(0); | setPage(0); | ||||
| setPageSize(parseInt(event.target.value, 10)); | setPageSize(parseInt(event.target.value, 10)); | ||||
| } | } | ||||
| if (serverSorting) { | |||||
| if (doLoad.params?.sort && doLoad.params?.direction) { | |||||
| setSortModel([{ | |||||
| field: doLoad.params.sort, | |||||
| sort: String(doLoad.params.direction).toLowerCase() | |||||
| }]); | |||||
| } else { | |||||
| setSortModel([]); | |||||
| } | |||||
| } | |||||
| set_doLoad(doLoad); | set_doLoad(doLoad); | ||||
| setLoading(true) | setLoading(true) | ||||
| } | } | ||||
| }, [doLoad]); | }, [doLoad]); | ||||
| const handleSortModelChange = (newModel) => { | |||||
| if (!serverSorting) return; | |||||
| setSortModel(newModel); | |||||
| setPage(0); | |||||
| const params = { ...(_doLoad.params || {}) }; | |||||
| if (newModel?.length > 0 && newModel[0].field && newModel[0].sort) { | |||||
| params.sort = newModel[0].field; | |||||
| params.direction = newModel[0].sort; | |||||
| } else { | |||||
| delete params.sort; | |||||
| delete params.direction; | |||||
| } | |||||
| params.start = 0; | |||||
| params.limit = pageSize; | |||||
| if (applySearch != undefined) { | |||||
| applySearch(params); | |||||
| } else { | |||||
| set_doLoad({ ..._doLoad, params }); | |||||
| setLoading(true); | |||||
| } | |||||
| }; | |||||
| useEffect(() => { | useEffect(() => { | ||||
| getDataList(); | getDataList(); | ||||
| }, [_doLoad, page]); | }, [_doLoad, page]); | ||||
| @@ -261,6 +296,9 @@ export function FiDataGrid({ rows, columns, sx, autoHeight = true, | |||||
| filterModel={{ items: _filterItems }} | filterModel={{ items: _filterItems }} | ||||
| loading={loading} | loading={loading} | ||||
| paginationMode={pagination ? "server" : undefined} | paginationMode={pagination ? "server" : undefined} | ||||
| sortingMode={serverSorting ? "server" : undefined} | |||||
| sortModel={serverSorting ? sortModel : undefined} | |||||
| onSortModelChange={serverSorting ? handleSortModelChange : undefined} | |||||
| sx={{ | sx={{ | ||||
| ..._sx, | ..._sx, | ||||
| '& .MuiDataGrid-virtualScroller': { | '& .MuiDataGrid-virtualScroller': { | ||||
| @@ -95,18 +95,37 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, onGridReady }) => | |||||
| start:0, | start:0, | ||||
| limit:10 | limit:10 | ||||
| }; | }; | ||||
| if (searchCriteria?.sort && searchCriteria?.direction) { | |||||
| temp.sort = searchCriteria.sort; | |||||
| temp.direction = searchCriteria.direction; | |||||
| } | |||||
| applySearch(temp); | applySearch(temp); | ||||
| }; | }; | ||||
| function resetForm() { | function resetForm() { | ||||
| setType([]); | setType([]); | ||||
| setStatus(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]); | setStatus(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]); | ||||
| setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14))) | |||||
| setMaxDate(DateUtils.dateValue(new Date())) | |||||
| const dateFrom = DateUtils.dateValue(new Date().setDate(new Date().getDate() - 14)); | |||||
| const dateTo = DateUtils.dateValue(new Date()); | |||||
| setMinDate(dateFrom); | |||||
| setMaxDate(dateTo); | |||||
| reset({ | reset({ | ||||
| appNo:"" | |||||
| appNo: "", | |||||
| careOf: "", | |||||
| contact: "" | |||||
| }); | |||||
| localStorage.setItem('searchCriteria', ""); | |||||
| // Reset form criteria and sorting first, then reload with backend default sort | |||||
| applySearch({ | |||||
| appNo: "", | |||||
| dateFrom, | |||||
| dateTo, | |||||
| contact: "", | |||||
| careOf: "", | |||||
| status: "", | |||||
| start: 0, | |||||
| limit: 10 | |||||
| }); | }); | ||||
| localStorage.setItem('searchCriteria',"") | |||||
| } | } | ||||
| return ( | return ( | ||||
| @@ -45,6 +45,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| id: 'appNo', | id: 'appNo', | ||||
| field: 'appNo', | field: 'appNo', | ||||
| headerName: intl.formatMessage({ id: 'applicationId' }), | headerName: intl.formatMessage({ id: 'applicationId' }), | ||||
| sortable: true, | |||||
| width: isMdOrLg ? 'auto' : 160, | width: isMdOrLg ? 'auto' : 160, | ||||
| flex: isMdOrLg ? 1 : undefined, | flex: isMdOrLg ? 1 : undefined, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| @@ -56,6 +57,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| id: 'created', | id: 'created', | ||||
| field: 'created', | field: 'created', | ||||
| headerName: intl.formatMessage({ id: 'submitDate' }), | headerName: intl.formatMessage({ id: 'submitDate' }), | ||||
| sortable: true, | |||||
| width: isMdOrLg ? 'auto' : 160, | width: isMdOrLg ? 'auto' : 160, | ||||
| flex: isMdOrLg ? 1 : undefined, | flex: isMdOrLg ? 1 : undefined, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| @@ -63,36 +65,11 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| return DateUtils.datetimeStr(params?.value); | return DateUtils.datetimeStr(params?.value); | ||||
| } | } | ||||
| }, | }, | ||||
| // { | |||||
| // id: 'contactPerson', | |||||
| // field: 'contactPerson', | |||||
| // headerName: '聯絡人', | |||||
| // flex: 2, | |||||
| // renderCell: (params) => { | |||||
| // let phone = JSON.parse(params.row.contactTelNo); | |||||
| // let faxNo = JSON.parse(params.row.contactFaxNo); | |||||
| // let contact = ""; | |||||
| // if (phone) { | |||||
| // contact = "電話: " + phone?.countryCode + " " + phone?.phoneNumber | |||||
| // } | |||||
| // if (faxNo && faxNo?.faxNumber) { | |||||
| // if (contact != "") | |||||
| // contact = contact + ", " | |||||
| // contact = contact + "傳真:" + faxNo?.countryCode + " " + faxNo?.faxNumber | |||||
| // } | |||||
| // return (<> | |||||
| // {params?.value}<br /> | |||||
| // {contact} | |||||
| // </>); | |||||
| // } | |||||
| // }, | |||||
| { | { | ||||
| id: 'remarks', | id: 'remarks', | ||||
| field: 'remarks', | field: 'remarks', | ||||
| headerName: isORGLoggedIn() ? intl.formatMessage({ id: 'gazetteCount2_1' }) : intl.formatMessage({ id: 'myRemarks' }), | headerName: isORGLoggedIn() ? intl.formatMessage({ id: 'gazetteCount2_1' }) : intl.formatMessage({ id: 'myRemarks' }), | ||||
| sortable: true, | |||||
| width: isMdOrLg ? 'auto' : 400, | width: isMdOrLg ? 'auto' : 400, | ||||
| flex: isMdOrLg ? 3 : undefined, | flex: isMdOrLg ? 3 : undefined, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| @@ -124,6 +101,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| id: 'status', | id: 'status', | ||||
| field: 'status', | field: 'status', | ||||
| headerName: intl.formatMessage({ id: 'status' }), | headerName: intl.formatMessage({ id: 'status' }), | ||||
| sortable: true, | |||||
| width: 200, | width: 200, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| renderCell: (params) => { | renderCell: (params) => { | ||||
| @@ -134,6 +112,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| field: 'actions', | field: 'actions', | ||||
| type: 'actions', | type: 'actions', | ||||
| headerName: '', | headerName: '', | ||||
| sortable: false, | |||||
| width: 150, | width: 150, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| cellClassName: 'actions', | cellClassName: 'actions', | ||||
| @@ -157,6 +136,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| <FiDataGrid | <FiDataGrid | ||||
| columns={columns} | columns={columns} | ||||
| customPageSize={10} | customPageSize={10} | ||||
| serverSorting | |||||
| getRowHeight={() => 'auto'} | getRowHeight={() => 'auto'} | ||||
| onRowDoubleClick={handleRowDoubleClick} | onRowDoubleClick={handleRowDoubleClick} | ||||
| applyGridOnReady = {applyGridOnReady} | applyGridOnReady = {applyGridOnReady} | ||||
| @@ -67,9 +67,9 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| const columns = [ | const columns = [ | ||||
| { | { | ||||
| field: 'actions', | |||||
| field: 'appNo', | |||||
| headerName: 'Application No.', | headerName: 'Application No.', | ||||
| sortable: false, | |||||
| sortable: true, | |||||
| width: 150, | width: 150, | ||||
| cellClassName: 'actions', | cellClassName: 'actions', | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| @@ -81,7 +81,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| id: 'mode', | id: 'mode', | ||||
| field: 'mode', | field: 'mode', | ||||
| headerName: 'Mode', | headerName: 'Mode', | ||||
| sortable: false, | |||||
| sortable: true, | |||||
| width: 100, | width: 100, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| renderCell: (params) => { | renderCell: (params) => { | ||||
| @@ -92,7 +92,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| id: 'status', | id: 'status', | ||||
| field: 'status', | field: 'status', | ||||
| headerName: 'Status', | headerName: 'Status', | ||||
| sortable: false, | |||||
| sortable: true, | |||||
| width: 240, | width: 240, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| renderCell: (params) => { | renderCell: (params) => { | ||||
| @@ -103,7 +103,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| id: 'withProof', | id: 'withProof', | ||||
| field: 'withProof', | field: 'withProof', | ||||
| headerName: 'With Proof', | headerName: 'With Proof', | ||||
| sortable: false, | |||||
| sortable: true, | |||||
| width: 120, | width: 120, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| renderCell: (params) => { | renderCell: (params) => { | ||||
| @@ -114,7 +114,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| id: 'created', | id: 'created', | ||||
| field: 'created', | field: 'created', | ||||
| headerName: 'Submit Date', | headerName: 'Submit Date', | ||||
| sortable: false, | |||||
| sortable: true, | |||||
| flex: 1, | flex: 1, | ||||
| minWidth: 200, | minWidth: 200, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| @@ -126,7 +126,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| id: 'contactPerson', | id: 'contactPerson', | ||||
| field: 'contactPerson', | field: 'contactPerson', | ||||
| headerName: 'Client / Payment Means', | headerName: 'Client / Payment Means', | ||||
| sortable: false, | |||||
| sortable: true, | |||||
| minWidth: 250, | minWidth: 250, | ||||
| flex: 2, | flex: 2, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| @@ -146,7 +146,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| id: 'issueNoAndCode', | id: 'issueNoAndCode', | ||||
| field: 'issueNoAndCode', | field: 'issueNoAndCode', | ||||
| headerName: 'Gazette Issue No. / Gazette Code', | headerName: 'Gazette Issue No. / Gazette Code', | ||||
| sortable: false, | |||||
| sortable: true, | |||||
| flex: 1.5, | flex: 1.5, | ||||
| minWidth: 350, | minWidth: 350, | ||||
| renderHeader: renderHeaderWithAria, | renderHeader: renderHeaderWithAria, | ||||
| @@ -220,6 +220,7 @@ export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnRea | |||||
| <FiDataGrid | <FiDataGrid | ||||
| checkboxSelection | checkboxSelection | ||||
| disableRowSelectionOnClick | disableRowSelectionOnClick | ||||
| serverSorting | |||||
| onRowSelectionModelChange={(newSelection) => { | onRowSelectionModelChange={(newSelection) => { | ||||
| setSelectedRowItems(newSelection); | setSelectedRowItems(newSelection); | ||||
| }} | }} | ||||
| @@ -96,6 +96,10 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, o | |||||
| start:0, | start:0, | ||||
| limit:10 | limit:10 | ||||
| }; | }; | ||||
| if (searchCriteria?.sort && searchCriteria?.direction) { | |||||
| temp.sort = searchCriteria.sort; | |||||
| temp.direction = searchCriteria.direction; | |||||
| } | |||||
| applySearch(temp); | applySearch(temp); | ||||
| // setSearchReady(true) | // setSearchReady(true) | ||||
| }; | }; | ||||
| @@ -117,14 +121,31 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, o | |||||
| setGroupSelected({}); | setGroupSelected({}); | ||||
| setSelectedStatus({key: 0, label: 'All', type: 'all'}); | setSelectedStatus({key: 0, label: 'All', type: 'all'}); | ||||
| setSelectedMode({key: 0, label: 'All', type: 'all'}); | setSelectedMode({key: 0, label: 'All', type: 'all'}); | ||||
| setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14))) | |||||
| setMaxDate(DateUtils.dateValue(new Date())) | |||||
| const dateFrom = DateUtils.dateValue(new Date().setDate(new Date().getDate() - 14)); | |||||
| const dateTo = DateUtils.dateValue(new Date()); | |||||
| setMinDate(dateFrom); | |||||
| setMaxDate(dateTo); | |||||
| reset({ | reset({ | ||||
| appNo:"", | appNo:"", | ||||
| contact:"", | contact:"", | ||||
| groupNo:"" | groupNo:"" | ||||
| }); | }); | ||||
| localStorage.setItem('searchCriteria',"") | |||||
| localStorage.setItem('searchCriteria',""); | |||||
| // Reset form criteria and sorting first, then reload with backend default sort | |||||
| applySearch({ | |||||
| appNo: "", | |||||
| dateFrom, | |||||
| dateTo, | |||||
| contact: "", | |||||
| status: "", | |||||
| orgId: "", | |||||
| issueId: "", | |||||
| groupNo: "", | |||||
| gazettGroup: "", | |||||
| mode: "", | |||||
| start: 0, | |||||
| limit: 10 | |||||
| }); | |||||
| } | } | ||||
| const getIssueLabel=(data)=> { | const getIssueLabel=(data)=> { | ||||