@@ -4,14 +4,15 @@ import { spaces } from "../common/variables";
44import DxcPaginator from "../paginator/Paginator" ;
55import DxcTable , { DxcActionsCell } from "../table/Table" ;
66import useTheme from "../useTheme" ;
7- import ResultsetTablePropsType , { Column } from "./types" ;
7+ import ResultsetTablePropsType , { Column , Row } from "./types" ;
88import icons from "./Icons" ;
99import { getMargin } from "../common/utils" ;
1010import CoreTokens from "../common/coreTokens" ;
1111
12- const normalizeSortValue = ( sortValue ) => ( typeof sortValue === "string" ? sortValue . toUpperCase ( ) : sortValue ) ;
12+ const normalizeSortValue = ( sortValue : string | React . ReactNode ) =>
13+ typeof sortValue === "string" ? sortValue . toUpperCase ( ) : sortValue ;
1314
14- const sortArray = ( index , order , resultset ) =>
15+ const sortArray = ( index : number , order : "ascending" | "descending" , resultset : Row [ ] [ ] ) =>
1516 resultset . slice ( ) . sort ( ( element1 , element2 ) => {
1617 const sortValueA = normalizeSortValue ( element1 [ index ] . sortValue || element1 [ index ] . displayValue ) ;
1718 const sortValueB = normalizeSortValue ( element2 [ index ] . sortValue || element2 [ index ] . displayValue ) ;
@@ -28,15 +29,20 @@ const sortArray = (index, order, resultset) =>
2829 return order === "descending" ? comparison * - 1 : comparison ;
2930 } ) ;
3031
31- const getMinItemsPerPageIndex = ( currentPageInternal , itemsPerPage , page ) =>
32+ const getMinItemsPerPageIndex = ( currentPageInternal : number , itemsPerPage : number , page : number ) =>
3233 currentPageInternal === 1 ? 0 : itemsPerPage * ( page - 1 ) ;
3334
34- const getMaxItemsPerPageIndex = ( minItemsPerPageIndex , itemsPerPage , resultset , page ) =>
35- minItemsPerPageIndex + itemsPerPage > resultset . length ? resultset . length : itemsPerPage * page - 1 ;
35+ const getMaxItemsPerPageIndex = (
36+ minItemsPerPageIndex : number ,
37+ itemsPerPage : number ,
38+ resultset : Row [ ] [ ] ,
39+ page : number
40+ ) => ( minItemsPerPageIndex + itemsPerPage > resultset . length ? resultset . length : itemsPerPage * page - 1 ) ;
3641
3742const DxcResultsetTable = ( {
3843 columns,
3944 rows,
45+ hidePaginator = false ,
4046 showGoToPage = true ,
4147 itemsPerPage = 5 ,
4248 itemsPerPageOptions,
@@ -81,7 +87,9 @@ const DxcResultsetTable = ({
8187 } ;
8288
8389 useEffect ( ( ) => {
84- rows . length > 0 ? changePage ( 1 ) : changePage ( 0 ) ;
90+ if ( ! hidePaginator ) {
91+ rows . length > 0 ? changePage ( 1 ) : changePage ( 0 ) ;
92+ }
8593 } , [ rows ] ) ;
8694
8795 return (
@@ -121,31 +129,33 @@ const DxcResultsetTable = ({
121129 </ tr >
122130 </ thead >
123131 < tbody >
124- { filteredResultset . map ( ( cells , index ) => (
125- < tr key = { `resultSetTableCell_${ page } _${ index } ` } >
126- { cells . map ( ( cellContent , index ) => (
127- < td key = { `resultSetTableCellContent_${ index } ` } > { cellContent . displayValue } </ td >
132+ { filteredResultset . map ( ( cells , rowIndex ) => (
133+ < tr key = { `resultSetTableCell_${ page } _${ rowIndex } ` } >
134+ { cells . map ( ( cellContent , cellIndex ) => (
135+ < td key = { `resultSetTableCellContent_${ cellIndex } ` } > { cellContent . displayValue } </ td >
128136 ) ) }
129137 </ tr >
130138 ) ) }
131139 </ tbody >
132140 </ DxcTable >
133- < DxcPaginator
134- totalItems = { rows . length }
135- itemsPerPage = { itemsPerPage }
136- itemsPerPageOptions = { itemsPerPageOptions }
137- itemsPerPageFunction = { itemsPerPageFunction }
138- currentPage = { page }
139- showGoToPage = { showGoToPage }
140- onPageChange = { goToPage }
141- tabIndex = { tabIndex }
142- />
141+ { ! hidePaginator && (
142+ < DxcPaginator
143+ totalItems = { rows . length }
144+ itemsPerPage = { itemsPerPage }
145+ itemsPerPageOptions = { itemsPerPageOptions }
146+ itemsPerPageFunction = { itemsPerPageFunction }
147+ currentPage = { page }
148+ showGoToPage = { showGoToPage }
149+ onPageChange = { goToPage }
150+ tabIndex = { tabIndex }
151+ />
152+ ) }
143153 </ DxcResultsetTableContainer >
144154 </ ThemeProvider >
145155 ) ;
146156} ;
147157
148- const calculateWidth = ( margin ) => `calc(100% - ${ getMargin ( margin , "left" ) } - ${ getMargin ( margin , "right" ) } )` ;
158+ const calculateWidth = ( margin : string | object ) => `calc(100% - ${ getMargin ( margin , "left" ) } - ${ getMargin ( margin , "right" ) } )` ;
149159
150160const DxcResultsetTableContainer = styled . div < { margin : ResultsetTablePropsType [ "margin" ] } > `
151161 width: ${ ( props ) => calculateWidth ( props . margin ) } ;
0 commit comments