File size: 4,904 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | import React from 'react';
import MUIDataTable, { ExpandButton } from '../../src/';
import TableRow from '@mui/material/TableRow';
import TableCell from '@mui/material/TableCell';
import { createTheme, ThemeProvider } from '@mui/material/styles';
class Example extends React.Component {
render() {
const columns = [
{
name: 'Name',
options: {
filter: true,
},
},
{
name: 'Title',
options: {
filter: true,
},
},
{
name: 'Location',
options: {
filter: false,
},
},
{
name: 'Age',
options: {
filter: true,
},
},
{
name: 'Salary',
options: {
filter: true,
sort: false,
},
},
];
const data = [
['Gabby George', 'Business Analyst', 'Minneapolis', 30, '$100,000'],
['Aiden Lloyd', 'Business Consultant', 'Dallas', 55, '$200,000'],
['Jaden Collins', 'Attorney', 'Santa Ana', 27, '$500,000'],
['Franky Rees', 'Business Analyst', 'St. Petersburg', 22, '$50,000'],
['Aaren Rose', 'Business Consultant', 'Toledo', 28, '$75,000'],
['Blake Duncan', 'Business Management Analyst', 'San Diego', 65, '$94,000'],
['Frankie Parry', 'Agency Legal Counsel', 'Jacksonville', 71, '$210,000'],
['Lane Wilson', 'Commercial Specialist', 'Omaha', 19, '$65,000'],
['Robin Duncan', 'Business Analyst', 'Los Angeles', 20, '$77,000'],
['Mel Brooks', 'Business Consultant', 'Oklahoma City', 37, '$135,000'],
['Harper White', 'Attorney', 'Pittsburgh', 52, '$420,000'],
['Kris Humphrey', 'Agency Legal Counsel', 'Laredo', 30, '$150,000'],
['Frankie Long', 'Industrial Analyst', 'Austin', 31, '$170,000'],
['Brynn Robbins', 'Business Analyst', 'Norfolk', 22, '$90,000'],
['Justice Mann', 'Business Consultant', 'Chicago', 24, '$133,000'],
['Addison Navarro', 'Business Management Analyst', 'New York', 50, '$295,000'],
['Jesse Welch', 'Agency Legal Counsel', 'Seattle', 28, '$200,000'],
['Eli Mejia', 'Commercial Specialist', 'Long Beach', 65, '$400,000'],
['Gene Leblanc', 'Industrial Analyst', 'Hartford', 34, '$110,000'],
['Danny Leon', 'Computer Scientist', 'Newark', 60, '$220,000'],
['Lane Lee', 'Corporate Counselor', 'Cincinnati', 52, '$180,000'],
['Jesse Hall', 'Business Analyst', 'Baltimore', 44, '$99,000'],
['Danni Hudson', 'Agency Legal Counsel', 'Tampa', 37, '$90,000'],
['Terry Macdonald', 'Commercial Specialist', 'Miami', 39, '$140,000'],
['Justice Mccarthy', 'Attorney', 'Tucson', 26, '$330,000'],
['Silver Carey', 'Computer Scientist', 'Memphis', 47, '$250,000'],
['Franky Miles', 'Industrial Analyst', 'Buffalo', 49, '$190,000'],
['Glen Nixon', 'Corporate Counselor', 'Arlington', 44, '$80,000'],
['Gabby Strickland', 'Business Process Consultant', 'Scottsdale', 26, '$45,000'],
['Mason Ray', 'Computer Scientist', 'San Francisco', 39, '$142,000'],
];
const options = {
filter: true,
filterType: 'dropdown',
responsive: 'standard',
expandableRows: true,
expandableRowsHeader: false,
expandableRowsOnClick: true,
isRowExpandable: (dataIndex, expandedRows) => {
if (dataIndex === 3 || dataIndex === 4) return false;
// Prevent expand/collapse of any row if there are 4 rows expanded already (but allow those already expanded to be collapsed)
if (expandedRows.data.length > 4 && expandedRows.data.filter(d => d.dataIndex === dataIndex).length === 0)
return false;
return true;
},
rowsExpanded: [0, 1],
renderExpandableRow: (rowData, rowMeta) => {
const colSpan = rowData.length + 1;
return (
<TableRow>
<TableCell colSpan={colSpan}>Custom expandable row option. Data: {JSON.stringify(rowData)}</TableCell>
</TableRow>
);
},
onRowExpansionChange: (curExpanded, allExpanded, rowsExpanded) =>
console.log(curExpanded, allExpanded, rowsExpanded),
};
const theme = createTheme({
overrides: {
MUIDataTableSelectCell: {
expandDisabled: {
// Soft hide the button.
visibility: 'hidden',
},
},
},
});
const components = {
ExpandButton: function(props) {
if (props.dataIndex === 3 || props.dataIndex === 4) return <div style={{ width: '24px' }} />;
return <ExpandButton {...props} />;
},
};
return (
<ThemeProvider theme={theme}>
<MUIDataTable
title={'ACME Employee list'}
data={data}
columns={columns}
options={options}
components={components}
/>
</ThemeProvider>
);
}
}
export default Example;
|