@@ -13,7 +13,7 @@ import { Pagination } from "./Pagination";
1313import type { PaginationProps } from "./Pagination" ;
1414import { TableHeader } from "./TableHeader" ;
1515import { TableRow } from "./TableRow" ;
16- import { SortType } from ' ../constants/sort' ;
16+ import { SortType } from " ../constants/sort" ;
1717import { defaultTheme } from "../constants/theme" ;
1818import { mergeThemeProps } from "../mergeThemeProps" ;
1919import type { ThemeProps } from "../types/theme" ;
@@ -76,13 +76,17 @@ export const MultiLevelTable: React.FC<MultiLevelTableProps> = ({
7676 disableSortBy : sortable ? col . sortable === false : true ,
7777 sortType : col . customSortFn ? SortType . Custom : SortType . Basic ,
7878 sortFn : col . customSortFn ,
79- Cell : ( { row, value } : { row : Row < DataItem > ; value : string | number } ) => {
79+ Cell : ( {
80+ row,
81+ value,
82+ } : {
83+ row : Row < DataItem > ;
84+ value : string | number ;
85+ } ) => {
8086 const item = row . original ;
8187
8288 return (
83- < div >
84- { col . render ? col . render ( value , item ) : value ?. toString ( ) }
85- </ div >
89+ < div > { col . render ? col . render ( value , item ) : value ?. toString ( ) } </ div >
8690 ) ;
8791 } ,
8892 Filter : col . filterable
@@ -122,8 +126,12 @@ export const MultiLevelTable: React.FC<MultiLevelTableProps> = ({
122126 initialState : { pageSize } as TableStateWithPagination < DataItem > ,
123127 // @ts -expect-error - sortTypes is not included in the type definition but is supported by react-table
124128 sortTypes : {
125- custom : ( rowA : Row < DataItem > , rowB : Row < DataItem > , columnId : string ) => {
126- const column = columns . find ( col => col . key === columnId ) ;
129+ custom : (
130+ rowA : Row < DataItem > ,
131+ rowB : Row < DataItem > ,
132+ columnId : string
133+ ) => {
134+ const column = columns . find ( ( col ) => col . key === columnId ) ;
127135
128136 if ( column ?. customSortFn )
129137 return column . customSortFn ( rowA . original , rowB . original , columnId ) ;
@@ -162,7 +170,6 @@ export const MultiLevelTable: React.FC<MultiLevelTableProps> = ({
162170 newSet . delete ( rowId ) ;
163171 else
164172 newSet . add ( rowId ) ;
165-
166173
167174 return newSet ;
168175 } ) ;
@@ -194,69 +201,87 @@ export const MultiLevelTable: React.FC<MultiLevelTableProps> = ({
194201 } ) ;
195202 } ;
196203
204+ const renderPagination = ( ) => {
205+ if ( renderCustomPagination )
206+ return renderCustomPagination ( {
207+ canPreviousPage,
208+ canNextPage,
209+ pageOptions,
210+ pageCount,
211+ pageIndex,
212+ pageSize : currentPageSize ,
213+ gotoPage,
214+ nextPage,
215+ previousPage,
216+ setPageSize,
217+ theme : mergedTheme ,
218+ } ) ;
219+
220+
221+ return (
222+ < Pagination
223+ canPreviousPage = { canPreviousPage }
224+ canNextPage = { canNextPage }
225+ pageOptions = { pageOptions }
226+ pageCount = { pageCount }
227+ pageIndex = { pageIndex }
228+ gotoPage = { gotoPage }
229+ nextPage = { nextPage }
230+ previousPage = { previousPage }
231+ pageSize = { currentPageSize }
232+ setPageSize = { setPageSize }
233+ theme = { mergedTheme }
234+ />
235+ ) ;
236+ } ;
237+
238+ const renderTableBody = ( ) => {
239+ return (
240+ < tbody { ...getTableBodyProps ( ) } >
241+ { page . map ( ( row ) => {
242+ prepareRow ( row ) ;
243+ const parentId = row . original . id ;
244+ const hasChildren = rowsMap . has ( parentId ) ;
245+
246+ return (
247+ < React . Fragment key = { parentId } >
248+ < TableRow
249+ row = { row }
250+ columns = { columns }
251+ hasChildren = { hasChildren }
252+ isExpanded = { expandedRows . has ( parentId ) }
253+ onToggle = { ( ) => hasChildren && toggleRow ( parentId ) }
254+ theme = { mergedTheme }
255+ expandIcon = { expandIcon }
256+ />
257+ { renderNestedRows ( parentId ) }
258+ </ React . Fragment >
259+ ) ;
260+ } ) }
261+ </ tbody >
262+ ) ;
263+ } ;
264+
197265 return (
198266 < div style = { { backgroundColor : mergedTheme . colors ?. background } } >
199- < table
200- { ...getTableProps ( ) }
201- className = "table-container"
202- style = { { borderColor : mergedTheme . table ?. cell ?. borderColor } }
203- >
204- < TableHeader headerGroups = { headerGroups } theme = { mergedTheme } sortable = { sortable }
205- ascendingIcon = { ascendingIcon }
206- descendingIcon = { descendingIcon } />
207- < tbody { ...getTableBodyProps ( ) } >
208- { page . map ( ( row ) => {
209- prepareRow ( row ) ;
210- const parentId = row . original . id ;
211- const hasChildren = rowsMap . has ( parentId ) ;
212-
213- return (
214- < React . Fragment key = { parentId } >
215- < TableRow
216- row = { row }
217- columns = { columns }
218- hasChildren = { hasChildren }
219- isExpanded = { expandedRows . has ( parentId ) }
220- onToggle = { ( ) => hasChildren && toggleRow ( parentId ) }
221- theme = { mergedTheme }
222- expandIcon = { expandIcon }
223- />
224- { renderNestedRows ( parentId ) }
225- </ React . Fragment >
226- ) ;
227- } ) }
228- </ tbody >
229- </ table >
267+ < div className = "table-wrapper" >
268+ < table
269+ { ...getTableProps ( ) }
270+ className = "table-container"
271+ style = { { borderColor : mergedTheme . table ?. cell ?. borderColor } }
272+ >
273+ < TableHeader
274+ headerGroups = { headerGroups }
275+ theme = { mergedTheme }
276+ sortable = { sortable }
277+ ascendingIcon = { ascendingIcon }
278+ descendingIcon = { descendingIcon }
279+ />
280+ { renderTableBody ( ) }
281+ </ table >
230282
231- { renderCustomPagination ? (
232- renderCustomPagination ( {
233- canPreviousPage,
234- canNextPage,
235- pageOptions,
236- pageCount,
237- pageIndex,
238- pageSize : currentPageSize ,
239- gotoPage,
240- nextPage,
241- previousPage,
242- setPageSize,
243- theme : mergedTheme ,
244- } )
245- ) : (
246- < Pagination
247- canPreviousPage = { canPreviousPage }
248- canNextPage = { canNextPage }
249- pageOptions = { pageOptions }
250- pageCount = { pageCount }
251- pageIndex = { pageIndex }
252- gotoPage = { gotoPage }
253- nextPage = { nextPage }
254- previousPage = { previousPage }
255- pageSize = { currentPageSize }
256- setPageSize = { setPageSize }
257- theme = { mergedTheme }
258- />
259- ) }
283+ { renderPagination ( ) }
284+ </ div >
260285 </ div >
261286 ) ;
262287} ;
0 commit comments