ConceptPortal-public/rsconcept/frontend/src/components/ui/DataTable/SelectAll.tsx

29 lines
775 B
TypeScript
Raw Normal View History

2023-09-10 20:17:18 +03:00
import { Table } from '@tanstack/react-table';
import CheckboxTristate from '@/components/ui/CheckboxTristate';
2023-09-10 20:17:18 +03:00
interface SelectAllProps<TData> {
2023-12-28 14:04:44 +03:00
table: Table<TData>;
2024-03-25 23:10:29 +03:00
setLastSelected: React.Dispatch<React.SetStateAction<string | undefined>>;
2023-09-10 20:17:18 +03:00
}
2024-03-25 23:10:29 +03:00
function SelectAll<TData>({ table, setLastSelected }: SelectAllProps<TData>) {
function handleChange(value: boolean | null) {
setLastSelected(undefined);
table.toggleAllPageRowsSelected(value !== false);
}
2023-09-10 20:17:18 +03:00
return (
<CheckboxTristate
2023-12-28 14:04:44 +03:00
tabIndex={-1}
title='Выделить все'
value={
!table.getIsAllPageRowsSelected() && table.getIsSomePageRowsSelected() ? null : table.getIsAllPageRowsSelected()
}
2024-03-25 23:10:29 +03:00
setValue={handleChange}
2023-12-28 14:04:44 +03:00
/>
);
2023-09-10 20:17:18 +03:00
}
2023-12-28 14:04:44 +03:00
export default SelectAll;