@@ -2,6 +2,8 @@ import { FC, useMemo, useState } from 'react';
22import {
33 expandable ,
44 ExpandableRowContent ,
5+ InnerScrollContainer ,
6+ OuterScrollContainer ,
57 Table ,
68 TableProps ,
79 Tbody ,
@@ -37,6 +39,10 @@ export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | '
3739 hasResizableColumns ?: boolean ;
3840 /** Toggles expandable */
3941 isExpandable ?: boolean ;
42+ /** Toogles sticky colums and headder */
43+ isSticky ?: boolean ;
44+ /** Toogles draggable rows */
45+ isDraggable ?: boolean ;
4046}
4147
4248export const DataViewTableBasic : FC < DataViewTableBasicProps > = ( {
@@ -48,6 +54,8 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
4854 bodyStates,
4955 hasResizableColumns,
5056 isExpandable,
57+ isSticky = false ,
58+ isDraggable = true ,
5159 ...props
5260} : DataViewTableBasicProps ) => {
5361 const { selection, activeState, isSelectable } = useInternalContext ( ) ;
@@ -70,13 +78,13 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
7078 const rowId = isDataViewTdObject ( firstCell ) ? ( firstCell as any ) . id : undefined ;
7179
7280 // Find the matching expanded content by row_id and column_id
73- const expandedRowContent = expandedRows ?. find (
81+ const expandedRowContent = isExpandable ? expandedRows ?. find (
7482 ( content ) => content . row_id === rowId && content . column_id === expandedColIndex
75- ) ;
83+ ) : undefined ;
7684
7785 return (
7886 < Tbody key = { rowIndex } isExpanded = { isRowExpanded } >
79- < Tr ouiaId = { `${ ouiaId } -tr-${ rowIndex } ` } { ...( rowIsObject && row ?. props ) } isContentExpanded = { isRowExpanded } isControlRow >
87+ < Tr ouiaId = { `${ ouiaId } -tr-${ rowIndex } ` } { ...( rowIsObject && row ?. props ) } isContentExpanded = { isRowExpanded } isControlRow draggable = { isDraggable } >
8088 { isSelectable && (
8189 < Td
8290 key = { `select-${ rowIndex } ` }
@@ -92,9 +100,9 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
92100 ) }
93101 { ( rowIsObject ? row . row : row ) . map ( ( cell , colIndex ) => {
94102 const cellIsObject = isDataViewTdObject ( cell ) ;
95- const cellExpandableContent = expandedRows ?. find (
103+ const cellExpandableContent = isExpandable ? expandedRows ?. find (
96104 ( content ) => content . row_id === rowId && content . column_id === colIndex
97- ) ;
105+ ) : undefined ;
98106 return (
99107 < Td
100108 key = { colIndex }
@@ -136,6 +144,20 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
136144 ) ;
137145 } ) , [ rows , isSelectable , isSelected , isSelectDisabled , onSelect , ouiaId , expandedRowsState , expandedColumnIndex , expandedRows , columns . length ] ) ;
138146
147+ if ( isSticky )
148+ {
149+ return (
150+ < OuterScrollContainer >
151+ < InnerScrollContainer >
152+ < Table aria-label = "Data table" ouiaId = { ouiaId } isExpandable = { isExpandable } { ...props } isStickyHeader >
153+ { activeHeadState || < DataViewTableHead columns = { columns } ouiaId = { ouiaId } hasResizableColumns = { hasResizableColumns } /> }
154+ { activeBodyState || renderedRows }
155+ </ Table >
156+ </ InnerScrollContainer >
157+ </ OuterScrollContainer >
158+ )
159+ }
160+ else
139161 return (
140162 < Table aria-label = "Data table" ouiaId = { ouiaId } isExpandable = { isExpandable } { ...props } >
141163 { activeHeadState || < DataViewTableHead columns = { columns } ouiaId = { ouiaId } hasResizableColumns = { hasResizableColumns } /> }
0 commit comments