@@ -4,7 +4,7 @@ import { useIntl } from '@edx/frontend-platform/i18n';
4
4
import { DataTable , TextFilter } from '@openedx/paragon' ;
5
5
import { connect } from 'react-redux' ;
6
6
import { useLocation , useNavigate } from 'react-router-dom' ;
7
- import { useMemo , useCallback , useEffect } from 'react' ;
7
+ import { useMemo , useCallback , useEffect , useState } from 'react' ;
8
8
import useCourseEnrollments from './data/hooks/useCourseEnrollments' ;
9
9
import { PAGE_SIZE } from '../../data/constants/table' ;
10
10
import {
@@ -37,6 +37,10 @@ const LearnerActivityTable = ({ id, enterpriseId, activity }) => {
37
37
const navigate = useNavigate ( ) ;
38
38
const { setTableHasData } = useTableData ( ) ;
39
39
40
+ const [ pagination , setPagination ] = useState ( {
41
+ pageIndex : 0 , //initial page index
42
+ pageSize : 5 , //default page size
43
+ } ) ;
40
44
// Parse the current page from URL query parameters - adjust for zero-based indexing
41
45
const queryParams = useMemo ( ( ) => new URLSearchParams ( location . search ) , [ location . search ] ) ;
42
46
const pageFromUrl = parseInt ( queryParams . get ( `${ id } -page` ) , 10 ) || 1 ; // Default to page 1 in URL
@@ -67,7 +71,7 @@ const LearnerActivityTable = ({ id, enterpriseId, activity }) => {
67
71
useEffect ( ( ) => {
68
72
fetchDataImmediate ( {
69
73
pageIndex : currentPageFromUrl ,
70
- pageSize : PAGE_SIZE ,
74
+ pageSize : pagination . pageSize ,
71
75
sortBy : [ ] ,
72
76
} , true ) ;
73
77
} , [ ] ) ;
@@ -77,6 +81,15 @@ const LearnerActivityTable = ({ id, enterpriseId, activity }) => {
77
81
setTableHasData ( id , hasData ) ;
78
82
} , [ id , hasData ] ) ;
79
83
84
+ useEffect ( ( ) => {
85
+ if ( setPagination ) {
86
+ setPagination ( ( pagination ) => ( {
87
+ pageIndex : 0 ,
88
+ pageSize : pagination . pageSize ,
89
+ } ) ) ;
90
+ }
91
+ } , [ setPagination ] ) ;
92
+
80
93
// Wrap fetchCourseEnrollments to update the URL when pagination changes
81
94
const fetchTableData = useCallback ( ( tableState ) => {
82
95
const newPageForUrl = tableState . pageIndex + 1 ; // Convert zero-based index to one-based for URL
@@ -184,15 +197,21 @@ const LearnerActivityTable = ({ id, enterpriseId, activity }) => {
184
197
defaultColumnValues = { { Filter : TextFilter } }
185
198
columns = { columns }
186
199
initialState = { {
187
- pageIndex : currentPageFromUrl , // Use page from URL
188
- pageSize : PAGE_SIZE ,
200
+ // pageIndex: currentPageFromUrl, // Use page from URL
201
+ // pageSize: PAGE_SIZE,
189
202
sortBy : [ { id : 'lastActivityDate' , desc : true } ] ,
190
203
selectedRowsOrdered : [ ] ,
191
204
} }
192
205
fetchData = { fetchTableData }
193
206
data = { courseEnrollments . results }
194
207
itemCount = { courseEnrollments . itemCount }
195
208
pageCount = { courseEnrollments . pageCount }
209
+ initialTableOptions = { {
210
+ onPaginationChange : setPagination ,
211
+ state : {
212
+ pagination
213
+ } ,
214
+ } }
196
215
/>
197
216
) ;
198
217
} ;
0 commit comments