You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/components/datatables/expand-column.tsx

46 lines
1.1 KiB

import { ChevronDown, ChevronUp } from 'lucide-react';
import { ColumnDef } from '@tanstack/react-table';
import { Button } from '@@/buttons';
export function buildExpandColumn<
T extends Record<string, unknown>
>(): ColumnDef<T> {
return {
id: 'expand',
header: ({ table }) => {
const hasExpandableItems = table.getExpandedRowModel().rows.length > 0;
return (
hasExpandableItems && (
<Button
onClick={table.getToggleAllRowsExpandedHandler()}
color="none"
icon={table.getIsAllRowsExpanded() ? ChevronDown : ChevronUp}
/>
)
);
},
cell: ({ row }) =>
row.getCanExpand() && (
<Button
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
row.toggleExpanded();
}}
color="none"
icon={row.getIsExpanded() ? ChevronDown : ChevronUp}
/>
),
enableColumnFilter: false,
enableGlobalFilter: false,
enableHiding: false,
meta: {
width: 40,
},
};
}