Another React Material Data Table
npm install @arterial/data-tableAnother React Material Data Table
``zsh`
npm install @arterial/data-table
#### Sass
`scss`
@use "@material/data-table/data-table.scss" as data-table;
@include data-table.core-styles;
@include data-table.theme-baseline;
#### CSS
`jsx`
import '@material/data-table/dist/mdc.data-table.css';
`jsx`
import { DataTable, DataTableCell, DataTableContent, ... } from '@arterial/data-table';
`jsxbaseline-header-row-${cellData}-cell
const numeric = [false, true, true, true, true];
const header = ['Dessert', 'Calories', 'Fat', 'Carbs', 'Protein (g)'];
const content = [
['Frozen yogurt', '159', '6', '24', '4'],
['Ice cream sandwich', '237', '9', '37', '4.3'],
['Eclair', '262', '16', '24', '6'],
];
function Demo() {
return (
{header.map((cellData, cellIndex) => (
key={}`
>
{cellData}
))}
{content.map((rowData, rowIndex) => (
}>baseline-${rowIndex}-row-${header[cellIndex]}-cell-${cellData}
{rowData.map((cellData, cellIndex) => (
key={}
>
{cellData}
))}
))}
);
}
`jsxcheckbox-${rowIndex}-row
const numeric = [false, true, true, true, true];
const header = ['Dessert', 'Calories', 'Fat', 'Carbs', 'Protein (g)'];
const content = [
['Frozen yogurt', '159', '6', '24', '4'],
['Ice cream sandwich', '237', '9', '37', '4.3'],
['Eclair', '262', '16', '24', '6'],
];
function initChecked() {
const checked = {};
content.forEach((_rowData, rowIndex) => {
checked[rowIndex] = false;
});
return checked;
}
function CheckboxTable() {
const [headerChecked, setHeaderChecked] = useState('');
const [bodyChecked, setBodyChecked] = useState(initChecked());
return (
{header.map((cellData, cellIndex) => (
}>${cellData}-checkbox
{cellIndex === 0 && (
checkboxId={}
checked={headerChecked === 'checked'}
indeterminate={headerChecked === 'indeterminate'}
onChange={data => {
Object.keys(bodyChecked).forEach(key => {
bodyChecked[key] = data.checked;
});
setHeaderChecked(data.checked ? 'checked' : '');
setBodyChecked({...bodyChecked});
}}
/>
)}
{cellData}
))}
{content.map((rowData, rowIndex) => (
key={}checkbox-${rowIndex}-row-${header[cellIndex]}-cell-${cellData}
>
{rowData.map((cellData, cellIndex) => (
}${cellData}-checkbox
>
{cellIndex === 0 && (
checkboxId={}``
checked={bodyChecked[rowIndex] === true}
onChange={data => {
bodyChecked[rowIndex] = data.checked;
const values = Object.values(bodyChecked);
const checked = values.find(checked => checked);
const noneChecked = checked
? false
: values.every(checked => !checked);
const unchecked = values.find(checked => !checked);
const allChecked = unchecked
? false
: values.every(checked => checked);
let header;
if (allChecked) {
header = 'checked';
} else if (noneChecked) {
header = '';
} else {
header = 'indeterminate';
}
setHeaderChecked(header);
setBodyChecked({...bodyChecked});
}}
/>
)}
{cellData}
))}
))}
);
}
| Name | Type | Description |
| --------- | ------ | --------------------------------------------- |
| children | node | Elements to be displayed within root element. |
| className | string | Classes to be applied to the root element. |
| label | string | Text to be displayed within the root element. |
| Name | Type | Description |
| --------- | ------ | --------------------------------------------- |
| children | node | Elements to be displayed within root element. |
| className | string | Classes to be applied to the root element. |
| Name | Type | Description |
| --------- | ------- | --------------------------------------------- |
| children | node | Elements to be displayed within root element. |
| className | string | Classes to be applied to the root element. |
| selected | boolean | Indicates whether the element is selected. |
| Name | Type | Description |
| ---------- | ------- | ----------------------------------------------------- |
| checkbox | boolean | Enables checkbox to be displayed within root element. |
| checkboxId | string | Id of the checkbox. |
| children | node | Elements to be displayed within root element. |
| className | string | Classes to be applied to the root element. |
| numeric | boolean | Enables a numeric variant. |
| Name | Type | Description |
| --------- | ------ | --------------------------------------------- |
| children | node | Elements to be displayed within root element. |
| className | string | Classes to be applied to the root element. |
| Name | Type | Description |
| --------- | ------- | --------------------------------------------- |
| children | node | Elements to be displayed within root element. |
| className | string | Classes to be applied to the root element. |
| selected | boolean | Indicates whether the element is selected. |
| Name | Type | Description |
| ---------- | ------- | ----------------------------------------------------- |
| checkbox | boolean | Enables checkbox to be displayed within root element. |
| checkboxId | string | Id of the checkbox. |
| children | node | Elements to be displayed within root element. |
| className | string | Classes to be applied to the root element. |
| numeric | boolean | Enables a numeric variant. |