File size: 4,150 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 143 144 145 146 147 148 149 150 151 152 153 154 | import React from "react";
import ReactDOM from "react-dom";
import MUIDataTable from "../../src/";
import { debounceSearchRender } from "../../src/";
import { Button } from '@mui/material';
class Example extends React.Component {
constructor(props) {
super(props);
const rand = (size) => {
return Math.floor( Math.random() * size );
};
const firstNames = ['Adam', 'Jack', 'Edward', 'Donna', 'Sarah', 'Suzie', 'Sam', 'RJ', 'Henry', 'Ryan', 'Ricky', 'James'];
const lastNames = ['Ronson', 'Johnson', 'Jackson', 'Campo', 'Edwards', 'Brown', 'Green', 'White', 'Simmons', 'Gates', 'Jobs'];
const titles = ['Owner', 'Unemployed', 'Burger Flipper', 'Coder', 'Business Analyst', 'Attorney', 'Consultant', 'Singer','Painter'];
const locations = ['New York', 'El Paso', 'DC', 'Dallas', 'Santa Ana','St. Petersburg', 'London','Paris'];
const salarys = ['$100,000', '$50,000', '$75,000', '$80,000'];
var data = [];
var name = '';
for (var ii = 0; ii < 5000; ii++) {
name = firstNames[ rand(firstNames.length)] + ' ' + lastNames[ rand(lastNames.length) ];
data.push({
name: name,
title: titles[ rand(titles.length)],
location: locations[ rand(locations.length) ],
salary: salarys[ rand(salarys.length )],
phone: '555-5555',
email: name.replace(/ /g, '_').toLowerCase() + '@example.com',
});
}
this.state = {
data: data
};
console.time('Render Time');
}
componentDidMount() {
console.timeEnd('Render Time');
}
render() {
const columns = [
{
name: "name",
label: "Name",
options: {
filter: true,
customBodyRenderLite: (dataIndex) => {
let val = this.state.data[dataIndex].name;
return val;
}
}
},
{
name: "title",
label: "Modified Title Label",
options: {
filter: true,
customBodyRenderLite: (dataIndex) => {
let val = this.state.data[dataIndex].title;
return val;
}
}
},
{
name: "location",
label: "Location",
options: {
filter: false,
}
},
{
name: "age",
label: "Age",
options: {
filter: true,
}
},
{
name: "salary",
label: "Salary",
options: {
filter: true,
sort: false,
customBodyRenderLite: (dataIndex) => {
let val = this.state.data[dataIndex].salary;
return val;
}
}
},
{
name: "phone",
label: "Phone",
options: {
filter: true,
sort: false,
customBodyRenderLite: (dataIndex) => {
let val = this.state.data[dataIndex].phone;
return val;
}
}
},
{
name: "email",
label: "E-mail",
options: {
filter: true,
sort: false,
customBodyRenderLite: (dataIndex) => {
let val = this.state.data[dataIndex].email;
return val;
}
}
}
];
const options = {
rowsPerPage: 100,
rowsPerPageOptions: [10, 100, 250, 500, 1000],
filter: true,
filterType: 'dropdown',
responsive: 'vertical',
tableBodyHeight:'500px',
customSearchRender: debounceSearchRender(500),
jumpToPage: true,
// These next two options allow you to make it so filters need to be confirmed.
confirmFilters: true,
// Calling the applyNewFilters parameter applies the selected filters to the table
customFilterDialogFooter: (currentFilterList, applyNewFilters) => {
return (
<div style={{ marginTop: '40px' }}>
<Button variant="contained" onClick={applyNewFilters}>Apply Filters</Button>
</div>
);
}
};
return (
<MUIDataTable title={"ACME Employee list"} data={this.state.data} columns={columns} options={options} />
);
}
}
export default Example;
|