File size: 4,613 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 138 139 140 141 142 |
import React from "react";
import ReactDOM from "react-dom";
import FormControlLabel from '@mui/material/FormControlLabel';
import TextField from '@mui/material/TextField';
import Switch from '@mui/material/Switch';
import MUIDataTable from "../../src/";
import Cities from "./cities";
class Example extends React.Component {
render() {
const columns = [
{
name: "Name",
options: {
filter: false,
customBodyRender: (value, tableMeta, updateValue) => (
<FormControlLabel
label=""
value={value}
control={<TextField value={value} />}
onChange={event => updateValue(event.target.value)}
/>
)
}
},
{
name: "Title",
options: {
filter: true,
}
},
{
name: "Location",
options: {
filter: true,
customBodyRender: (value, tableMeta, updateValue) => {
return (
<Cities
value={value}
index={tableMeta.columnIndex}
change={event => updateValue(event)}
/>
);
},
}
},
{
name: "Age",
options: {
filter: false,
customBodyRender: (value, tableMeta, updateValue) => (
<FormControlLabel
label=""
control={<TextField value={value || ''} type='number' />}
onChange={event => updateValue(event.target.value)}
/>
)
}
},
{
name: "Salary",
options: {
filter: true,
customBodyRender: (value, tableMeta, updateValue) => {
const nf = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
return nf.format(value);
}
}
},
{
name: "Active",
options: {
filter: true,
customBodyRender: (value, tableMeta, updateValue) => {
return (
<FormControlLabel
label={value ? "Yes" : "No"}
value={value ? "Yes" : "No"}
control={
<Switch color="primary" checked={value} value={value ? "Yes" : "No"} />
}
onChange={event => {
updateValue(event.target.value === "Yes" ? false : true);
}}
/>
);
}
}
}
];
const data = [
["Robin Duncan", "Business Analyst", "Los Angeles", null, 77000, false],
["Mel Brooks", "Business Consultant", "Oklahoma City", 37, null, true],
["Harper White", "Attorney", "Pittsburgh", 52, 420000, false],
["Kris Humphrey", "Agency Legal Counsel", "Laredo", 30, 150000, true],
["Frankie Long", "Industrial Analyst", "Austin", 31, 170000, false],
["Brynn Robbins", "Business Analyst", "Norfolk", 22, 90000, true],
["Justice Mann", "Business Consultant", "Chicago", 24, 133000, false],
["Addison Navarro", "Business Management Analyst", "New York", 50, 295000, true],
["Jesse Welch", "Agency Legal Counsel", "Seattle", 28, 200000, false],
["Eli Mejia", "Commercial Specialist", "Long Beach", 65, 400000, true],
["Gene Leblanc", "Industrial Analyst", "Hartford", 34, 110000, false],
["Danny Leon", "Computer Scientist", "Newark", 60, 220000, true],
["Lane Lee", "Corporate Counselor", "Cincinnati", 52, 180000, false],
["Jesse Hall", "Business Analyst", "Baltimore", 44, 99000, true],
["Danni Hudson", "Agency Legal Counsel", "Tampa", 37, 90000, false],
["Terry Macdonald", "Commercial Specialist", "Miami", 39, 140000, true],
["Justice Mccarthy", "Attorney", "Tucson", 26, 330000, false],
["Silver Carey", "Computer Scientist", "Memphis", 47, 250000, true],
["Franky Miles", "Industrial Analyst", "Buffalo", 49, 190000, false],
["Glen Nixon", "Corporate Counselor", "Arlington", 44, 80000, true],
["Gabby Strickland", "Business Process Consultant", "Scottsdale", 26, 45000, false],
["Mason Ray", "Computer Scientist", "San Francisco", 39, 142000, true]
];
const options = {
filter: true,
filterType: 'dropdown',
responsive: 'standard'
};
return (
<MUIDataTable title={"ACME Employee list"} data={data} columns={columns} options={options} />
);
}
}
export default Example;
|