-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableRow.js
More file actions
131 lines (119 loc) · 4.09 KB
/
TableRow.js
File metadata and controls
131 lines (119 loc) · 4.09 KB
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
import React from 'react';
import Paper from '@material-ui/core/Paper';
import { Plugin, Template, TemplatePlaceholder } from "@devexpress/dx-react-core";
import { FilteringState, IntegratedFiltering, SortingState, IntegratedSorting } from '@devexpress/dx-react-grid';
import { Grid, VirtualTable, TableHeaderRow, TableFilterRow, DragDropProvider,
TableColumnReordering, ColumnChooser, TableColumnVisibility,
Toolbar,
} from '@devexpress/dx-react-grid-material-ui';
import DateRange from '@material-ui/icons/DateRange';
import { fade } from '@material-ui/core/styles/colorManipulator';
import { withStyles } from '@material-ui/core/styles';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTerminal } from '@fortawesome/free-solid-svg-icons'
import IconButton from '@material-ui/core/IconButton';
import Tooltip from '@material-ui/core/Tooltip';
const styles = theme => ({
tableStriped: {
'& tbody tr:nth-of-type(odd)': {
backgroundColor: fade(theme.palette.primary.main, 0.15),
},
},
headerCell: {
'&': {
color: '#000',
fontWeight: 800,
}
},
});
const FilterIcon = ({ type, ...restProps }) => {
if (type === 'month') return <DateRange {...restProps} />;
return <TableFilterRow.Icon type={type} {...restProps} />;
};
const TableComponentBase = ({ classes, ...restProps }) => (
<VirtualTable.Table
{...restProps}
className={classes.tableStriped}
/>
);
const TableHeaderComponentBase = ({ classes, ...restProps }) => (
<TableHeaderRow.Cell
{...restProps}
className={classes.headerCell}
/>
);
const Root = props => <Grid.Root {...props} style={{ height: '100%' }} />;
export const TableComponent = withStyles(styles, { name: 'TableComponent' })(TableComponentBase);
export const TableHeaderComponent = withStyles(styles, { name: 'TableHeaderComponent' })(TableHeaderComponentBase);
class TableRow extends React.PureComponent {
getCellValue(row, columnName) {
return columnName === "index"
? this.state.data.indexOf(row)
: row[columnName];
}
getRowId = (row) => {
return this.props.data.indexOf(row);
}
render() {
const CustomToolbarMarkup = () => {
const {
handleVisibleChange
} = this.props
return (
<Plugin name="customToolbarMarkup">
<Template name="toolbarContent">
<Tooltip title="Show Console" aria-label="showConsole">
<IconButton aria-label="consoleButton" onClick={() => handleVisibleChange(true)}>
<FontAwesomeIcon icon={faTerminal} size="sm" />
</IconButton>
</Tooltip>
<TemplatePlaceholder />
</Template>
</Plugin>)
};
const rows = this.props.data;
const columns = Object.keys(rows[0]).map(row => ({
name: row,
title: row,
}));
return (
<Paper>
<Grid
rows={rows}
columns={columns}
getRowId={this.getRowId}
rootComponent={Root}
>
<DragDropProvider />
<FilteringState defaultFilters={[]} />
<SortingState defaultSorting={[{ columnName: 'row', direction: 'asc' }]} />
<IntegratedFiltering />
<IntegratedSorting />
<VirtualTable
height={"auto"}
tableComponent={TableComponent}
/>
{/* <TableColumnResizing defaultColumnWidths /> */}
<TableHeaderRow
showSortingControls
cellComponent={TableHeaderComponent}
/>
<TableColumnReordering
defaultOrder={columns.map(column => column.name)}
/>
<TableFilterRow
showFilterSelector
iconComponent={FilterIcon}
/>
<TableColumnVisibility
onHiddenColumnNamesChange={change => console.info(`Columns filtered: ${change}`)}
/>
<Toolbar />
<ColumnChooser />
<CustomToolbarMarkup />
</Grid>
</Paper>
);
}
}
export default TableRow