import { useState } from 'react'; import { Table, Thead, Tr, Th, Tbody, Td, InnerScrollContainer } from '@patternfly/react-table'; import { PageSection } from '@patternfly/react-core'; import { DashboardWrapper } from '@patternfly/react-table/dist/esm/demos/DashboardWrapper'; type Direction = 'asc' | 'desc' | undefined; interface Fact { name: string; state: string; detail1: string; detail2: string; detail3: string; detail4: string; detail5: string; detail6: string; detail7: string; detail8: string; detail9: string; detail10: string; detail11: string; detail12: string; detail13: string; detail14: string; } export const TableStickyFirstColumn = () => { const facts = Array.from( { length: 9 }, (_, index) => ({ name: `Fact ${index + 1}`, state: `State ${index + 1}`, detail1: `Test cell ${index + 1}-3`, detail2: `Test cell ${index + 1}-4`, detail3: `Test cell ${index + 1}-5`, detail4: `Test cell ${index + 1}-6`, detail5: `Test cell ${index + 1}-7`, detail6: `Test cell ${index + 1}-8`, detail7: `Test cell ${index + 1}-9`, detail8: `Test cell ${index + 1}-10`, detail9: `Test cell ${index + 1}-11`, detail10: `Test cell ${index + 1}-12`, detail11: `Test cell ${index + 1}-13`, detail12: `Test cell ${index + 1}-14`, detail13: `Test cell ${index + 1}-15`, detail14: `Test cell ${index + 1}-16` }) ); const columnNames = { name: 'Fact', state: 'State', header3: 'Header 3', header4: 'Header 4', header5: 'Header 5', header6: 'Header 6', header7: 'Header 7', header8: 'Header 8', header9: 'Header 9', header10: 'Header 10', header11: 'Header 11', header12: 'Header 12', header13: 'Header 13', header14: 'Header 14', header15: 'Header 15', header16: 'Header 16' }; const [activeSortIndex, setActiveSortIndex] = useState(-1); const [activeSortDirection, setActiveSortDirection] = useState('asc'); const getSortableRowValues = (fact: Fact) => { const { name, state, detail1, detail2, detail3, detail4, detail5, detail6, detail7, detail8, detail9, detail10, detail11, detail12, detail13, detail14 } = fact; return [ name, state, detail1, detail2, detail3, detail4, detail5, detail6, detail7, detail8, detail9, detail10, detail11, detail12, detail13, detail14 ]; }; let sortedFacts = facts; if (activeSortIndex > -1) { sortedFacts = facts.sort((a, b) => { const aValue = getSortableRowValues(a)[activeSortIndex]; const bValue = getSortableRowValues(b)[activeSortIndex]; if (aValue === bValue) { return 0; } if (activeSortDirection === 'asc') { return aValue > bValue ? 1 : -1; } else { return bValue > aValue ? 1 : -1; } }); } const getSortParams = (columnIndex: number) => ({ sortBy: { index: activeSortIndex, direction: activeSortDirection }, onSort: (_event: React.MouseEvent, index: number, direction: Direction) => { setActiveSortIndex(index); setActiveSortDirection(direction); }, columnIndex }); return ( {sortedFacts.map((fact) => ( ))}
{columnNames.name} {columnNames.state} {columnNames.header3} {columnNames.header4} {columnNames.header5} {columnNames.header6} {columnNames.header7} {columnNames.header8} {columnNames.header9} {columnNames.header10} {columnNames.header11} {columnNames.header12} {columnNames.header13} {columnNames.header14} {columnNames.header15} {columnNames.header16}
{fact.name} {fact.state} {fact.detail1} {fact.detail2} {fact.detail3} {fact.detail4} {fact.detail5} {fact.detail6} {fact.detail7} {fact.detail8} {fact.detail9} {fact.detail10} {fact.detail11} {fact.detail12} {fact.detail13} {fact.detail14}
); };