) {
const isMobile = useMediaQuery('(max-width: 640px)')
const showMobile = isMobile && !props.hideMobile
const toolbarNode = renderToolbar(props)
const mobileNode = renderMobile(props, showMobile)
const desktopNode = renderDesktop(props, showMobile)
return (
<>
{toolbarNode}
{mobileNode}
{desktopNode}
{props.afterTable}
{/* Bulk actions are typically a fixed-position toolbar; let the consumer
handle its own visibility, we just gate it to non-mobile. */}
{!showMobile && props.bulkActions}
{props.showPagination !== false &&
(props.paginationInFooter !== false ? (
) : (
))}
>
)
}
function renderToolbar(
props: DataTablePageProps
): React.ReactNode {
if (props.toolbar !== undefined) {
return props.toolbar
}
if (props.toolbarProps === null) {
return null
}
if (props.toolbarProps) {
return
}
return null
}
function renderMobile(
props: DataTablePageProps,
showMobile: boolean
): React.ReactNode {
if (!showMobile) return null
if (props.mobile !== undefined) return props.mobile
const ownGetRowClassName = props.getRowClassName
const mobileGetRowClassName =
props.mobileProps?.getRowClassName ??
(ownGetRowClassName
? (row: Row) => ownGetRowClassName(row, { isMobile: true })
: undefined)
return (
)
}
function renderDesktop(
props: DataTablePageProps,
showMobile: boolean
): React.ReactNode {
if (showMobile) return null
const rows = props.table.getRowModel().rows
const isFetchingOnly = props.isFetching && !props.isLoading
return (
{props.table.getHeaderGroups().map((headerGroup) => (
{headerGroup.headers.map((header) => (
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
))}
))}
{props.isLoading ? (
) : rows.length === 0 ? (
{props.emptyAction}
) : (
rows.map((row) => {
if (props.renderRow) {
return props.renderRow(row)
}
return (
)
})
)}
)
}
function DefaultRow({
row,
className,
}: {
row: Row
className?: string
}) {
return (
{row.getVisibleCells().map((cell) => (
{flexRender(cell.column.columnDef.cell, cell.getContext())}
))}
)
}