react-table#HeaderGroup TypeScript Examples
The following examples show how to use
react-table#HeaderGroup.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From ke with MIT License | 6 votes |
mountHeader = (headerGroups: HeaderGroup[]): ReactNode =>
headerGroups.map((headerGroup: HeaderGroup) => (
<Flex flex={1} flexDirection="row" {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((column: ColumnType) => (
<TableCell p={4} key={column.id} bg="gray.100" {...column.getHeaderProps()} justifyContent="space-between">
<Flex flexDirection="column">
<Text fontWeight="bold">{column.render('Header')}</Text>
</Flex>
</TableCell>
))}
</Flex>
))
Example #2
Source File: product-table-config.tsx From admin with MIT License | 6 votes |
ProductHeader = ({
headerGroup,
}: {
headerGroup: HeaderGroup<Product>
}) => {
return (
<Table.HeadRow {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((col) => (
<Table.HeadCell {...col.getHeaderProps(col.getSortByToggleProps())}>
{col.render("Header")}
</Table.HeadCell>
))}
</Table.HeadRow>
)
}
Example #3
Source File: collection.tsx From admin with MIT License | 6 votes |
CollectionsHeader = ({
headerGroup,
}: {
headerGroup: HeaderGroup<ProductCollection>
}) => {
return (
<Table.HeadRow {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((col) => (
<Table.HeadCell
className="w-[100px]"
{...col.getHeaderProps(col.getSortByToggleProps())}
>
{col.render("Header")}
</Table.HeadCell>
))}
</Table.HeadRow>
)
}
Example #4
Source File: groups.tsx From admin with MIT License | 6 votes |
CustomerGroupsHeader = ({
headerGroup,
}: {
headerGroup: HeaderGroup<CustomerGroup>
}) => {
return (
<Table.HeadRow {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((col) => (
<Table.HeadCell
className="w-[100px]"
{...col.getHeaderProps(col.getSortByToggleProps())}
>
{col.render("Header")}
</Table.HeadCell>
))}
</Table.HeadRow>
)
}
Example #5
Source File: products.tsx From admin with MIT License | 6 votes |
ProductsHeader = ({
headerGroup,
}: {
headerGroup: HeaderGroup<Product>
}) => {
return (
<Table.HeadRow {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((col) => (
<Table.HeadCell
className="w-[100px]"
{...col.getHeaderProps(col.getSortByToggleProps())}
>
{col.render("Header")}
</Table.HeadCell>
))}
</Table.HeadRow>
)
}
Example #6
Source File: tags.tsx From admin with MIT License | 6 votes |
TagHeader = ({
headerGroup,
}: {
headerGroup: HeaderGroup<ProductTag>
}) => {
return (
<Table.HeadRow {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((col) => (
<Table.HeadCell
{...col.getHeaderProps(col.getSortByToggleProps())}
className="w-[20px]"
>
{col.render("Header")}
</Table.HeadCell>
))}
</Table.HeadRow>
)
}
Example #7
Source File: types.tsx From admin with MIT License | 6 votes |
TypesHeader = ({
headerGroup,
}: {
headerGroup: HeaderGroup<ProductType>
}) => {
return (
<Table.HeadRow {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((col) => (
<Table.HeadCell
className="w-[100px]"
{...col.getHeaderProps(col.getSortByToggleProps())}
>
{col.render("Header")}
</Table.HeadCell>
))}
</Table.HeadRow>
)
}
Example #8
Source File: index.tsx From admin with MIT License | 6 votes |
ProductHeader = ({
headerGroup,
}: {
headerGroup: HeaderGroup<Product>
}) => {
return (
<Table.HeadRow {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((col) => (
<Table.HeadCell {...col.getHeaderProps(col.getSortByToggleProps())}>
{col.render("Header")}
</Table.HeadCell>
))}
</Table.HeadRow>
)
}
Example #9
Source File: header.component.spec.tsx From master-frontend-lemoncode with MIT License | 5 votes |
describe('common/table/HeaderComponent', () => {
it('should be rendered as expected passing required properties', () => {
// Arrange
const props = {
headerGroups: ([
{
getHeaderGroupProps: jest.fn(),
headers: [
{
getHeaderProps: jest.fn(),
render: jest.fn().mockReturnValue('Test label'),
},
],
},
] as unknown) as HeaderGroup[],
};
// Act
const { getByText } = render(<HeaderComponent {...props} />);
// Assert
expect(getByText('Test label')).toBeInTheDocument();
});
it('should render two columns passing two columns', () => {
// Arrange
const props = {
headerGroups: ([
{
getHeaderGroupProps: jest.fn(),
headers: [
{
getHeaderProps: jest.fn(),
render: jest.fn().mockReturnValue('Test label 1'),
},
],
},
{
getHeaderGroupProps: jest.fn(),
headers: [
{
getHeaderProps: jest.fn(),
render: jest.fn().mockReturnValue('Test label 2'),
},
],
},
] as unknown) as HeaderGroup[],
};
// Act
const { getByText } = render(<HeaderComponent {...props} />);
// Assert
expect(getByText('Test label 1')).toBeInTheDocument();
expect(getByText('Test label 2')).toBeInTheDocument();
});
});
Example #10
Source File: DisplayTable.tsx From devex with GNU General Public License v3.0 | 5 votes |
DisplayTable: React.FC<IDisplayTableParams<DsBlockObj | TxBlockObj | TransactionDetails | TransactionStatus>> =
({ columns, data }) => {
const { getTableProps, headerGroups, rows, prepareRow } = useTable<DsBlockObj | TxBlockObj | TransactionDetails | TransactionStatus>({
columns,
data,
})
return (
<div className='display-table'>
<table {...getTableProps()}>
<thead>
{headerGroups.map((headerGroup: HeaderGroup<DsBlockObj | TxBlockObj | TransactionDetails | TransactionStatus>) => (
<tr {...headerGroup.getHeaderGroupProps()} key={headerGroup.getHeaderGroupProps().key}>
{headerGroup.headers.map((column) => (
<th
{...column.getHeaderProps()}
key={column.getHeaderProps().key}
id={column.id}
>
{column.render("Header")}
</th>
))}
</tr>
))}
</thead>
<tbody>
{rows.map((row: Row<DsBlockObj | TxBlockObj | TransactionDetails | TransactionStatus >) => {
prepareRow(row)
return (
<tr {...row.getRowProps()} key={row.getRowProps().key}>
{row.cells.map((cell: Cell<DsBlockObj | TxBlockObj | TransactionDetails | TransactionStatus>) => {
return (
<td {...cell.getCellProps()}
key={cell.getCellProps().key}>
{cell.render('Cell')}
</td>
)
})}
</tr>
);
}
)}
</tbody>
</table>
</div>
);
}
Example #11
Source File: ViewAllTable.tsx From devex with GNU General Public License v3.0 | 4 votes |
ViewAllTable: React.FC<IViewAllTableParams<DsBlockObj | TxBlockObj | TransactionDetails>> =
({ columns, data, isLoading, fetchData, pageCount: controlledPageCount }) => {
const { getTableProps,
getTableBodyProps,
headerGroups,
prepareRow,
page,
canPreviousPage,
canNextPage,
pageCount,
gotoPage,
nextPage,
previousPage,
// Get the state from the instance
state: { pageIndex } } = useTable<DsBlockObj | TxBlockObj | TransactionDetails>({
columns,
data,
initialState: { pageIndex: 0 },
manualPagination: true,
pageCount: controlledPageCount,
}, usePagination)
const fetchDataDebounce = useAsyncDebounce(fetchData, 300)
useEffect(() => {
fetchDataDebounce({ pageIndex })
// fetchDataDebounce changes when fetchData function changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pageIndex, fetchData])
const generatePagination = useCallback((currentPage: number, pageCount: number, delta = 2) => {
const separate = (a: number, b: number, isLower: boolean) => {
const temp = b - a
if (temp === 0)
return [a]
else if (temp === 1)
return [a, b]
else if (temp === 2)
return [a, a + 1, b]
else
return [a, isLower ? -1 : -2, b]
}
return Array(delta * 2 + 1)
.fill(0)
.map((_, index) => currentPage - delta + index)
.filter(page => 0 < page && page <= pageCount)
.flatMap((page, index, { length }) => {
if (!index) {
return separate(1, page, true)
}
if (index === length - 1) {
return separate(page, pageCount, false)
}
return [page]
})
}, [])
return (
<>
<BRow>
<BCol className='align-self-center pl-3'>
{data.length === 0
? null
: <span className='subtext'>Items Per Page: <strong>10</strong></span>}
</BCol>
<BCol>
<Pagination className='justify-content-end'>
<Pagination.Prev onClick={() => previousPage()} disabled={!canPreviousPage} />
{generatePagination(pageIndex + 1, pageCount).map((page) => {
if (page === -1)
return <Pagination.Ellipsis key={page} onClick={() => gotoPage(pageIndex - 5)} />
else if (page === -2)
return <Pagination.Ellipsis key={page} onClick={() => gotoPage(pageIndex + 5)} />
else if (page === pageIndex + 1)
return <Pagination.Item key={page} active>{page}</Pagination.Item>
else
return <Pagination.Item key={page} onClick={() => gotoPage(Number(page) - 1)}>{page}</Pagination.Item>
})}
<Pagination.Next onClick={() => nextPage()} disabled={!canNextPage} />
</Pagination>
</BCol>
</BRow>
<div className='viewall-table table'>
{isLoading ? <div className='center-spinner mt-4'><Spinner animation="border" /></div> : null}
<table {...getTableProps()}>
<thead>
{headerGroups.map((headerGroup: HeaderGroup<DsBlockObj | TxBlockObj | TransactionDetails>) => (
<tr {...headerGroup.getHeaderGroupProps()} key={headerGroup.getHeaderGroupProps().key} >
{headerGroup.headers.map((column) => (
<th {...column.getHeaderProps()} key={column.getHeaderProps().key} id={column.id}>
{column.render('Header')}
</th>
))}
</tr>
))}
</thead>
<tbody style={isLoading ? { opacity: '0.5' } : {}}{...getTableBodyProps()}>
{page.map((row: Row<DsBlockObj | TxBlockObj | TransactionDetails>) => {
prepareRow(row)
return (
<tr {...row.getRowProps()} key={row.getRowProps().key}>
{row.cells.map((cell: Cell<DsBlockObj | TxBlockObj | TransactionDetails>) => {
return (
<td {...cell.getCellProps()}
key={cell.getCellProps().key}>
{cell.render('Cell')}
</td>
)
})}
</tr>
)
})}
</tbody>
</table>
</div>
</>
)
}