Portal/rsconcept/frontend/src/components/DataTable/SelectAll.tsx

31 lines
722 B
TypeScript
Raw Normal View History

'use no memo';
2024-06-07 20:17:03 +03:00
import { Table } from '@tanstack/react-table';
import { CheckboxTristate } from '../Input';
2024-06-07 20:17:03 +03:00
interface SelectAllProps<TData> {
table: Table<TData>;
resetLastSelected: () => void;
2024-06-07 20:17:03 +03:00
}
function SelectAll<TData>({ table, resetLastSelected }: SelectAllProps<TData>) {
2024-06-07 20:17:03 +03:00
function handleChange(value: boolean | null) {
resetLastSelected();
2024-06-07 20:17:03 +03:00
table.toggleAllPageRowsSelected(value !== false);
}
return (
<CheckboxTristate
tabIndex={-1}
title='Выделить все'
value={
!table.getIsAllPageRowsSelected() && table.getIsSomePageRowsSelected() ? null : table.getIsAllPageRowsSelected()
}
onChange={handleChange}
2024-06-07 20:17:03 +03:00
/>
);
}
export default SelectAll;