jattac.libs.web.responsive-table 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -7
- package/dist/UI/ResponsiveTable.d.ts +8 -3
- package/dist/index.js +30 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Styles/ResponsiveTable.module.css +15 -0
- package/src/UI/ResponsiveTable.tsx +56 -52
package/README.md
CHANGED
|
@@ -37,13 +37,6 @@ See docs for more details on customization.
|
|
|
37
37
|
|
|
38
38
|
Column definitions can also be a function allowing dynamic configurations per row.
|
|
39
39
|
|
|
40
|
-
## Styling
|
|
41
|
-
|
|
42
|
-
Use CSS modules or global styles to customize visual layout:
|
|
43
|
-
|
|
44
|
-
- '.responsiveTable': Root table
|
|
45
|
-
- '.card': Mobile card containers
|
|
46
|
-
|
|
47
40
|
## Props
|
|
48
41
|
|
|
49
42
|
Prop definitions provide detailed specification of component contract.
|
|
@@ -63,6 +56,9 @@ interface IProps<TData> {
|
|
|
63
56
|
|
|
64
57
|
/** row click handler */
|
|
65
58
|
onRowClicked?: (row: TData) => void;
|
|
59
|
+
|
|
60
|
+
/** not data component */
|
|
61
|
+
noDataComponent?: ReactNode;
|
|
66
62
|
}
|
|
67
63
|
```
|
|
68
64
|
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
import React, { Component } from
|
|
2
|
-
import IResponsiveTableColumnDefinition from
|
|
1
|
+
import React, { Component, ReactNode } from 'react';
|
|
2
|
+
import IResponsiveTableColumnDefinition from '../Data/IResponsiveTableColumnDefinition';
|
|
3
3
|
type ColumnDefinition<TData> = IResponsiveTableColumnDefinition<TData> | ((data: TData, rowIndex?: number) => IResponsiveTableColumnDefinition<TData>);
|
|
4
4
|
interface IProps<TData> {
|
|
5
5
|
columnDefinitions: ColumnDefinition<TData>[];
|
|
6
6
|
data: TData[];
|
|
7
|
+
noDataComponent?: ReactNode;
|
|
7
8
|
}
|
|
8
9
|
interface IState {
|
|
9
10
|
isMobile: boolean;
|
|
10
11
|
}
|
|
11
12
|
declare class ResponsiveTable<TData> extends Component<IProps<TData>, IState> {
|
|
12
13
|
constructor(props: IProps<TData>);
|
|
14
|
+
private get data();
|
|
15
|
+
private get noDataSvg();
|
|
16
|
+
private get hasData();
|
|
17
|
+
private get noDataComponent();
|
|
13
18
|
componentDidMount(): void;
|
|
14
19
|
componentWillUnmount(): void;
|
|
15
20
|
handleResize: () => void;
|
|
16
21
|
private getColumnDefinition;
|
|
17
|
-
render(): React.JSX.Element;
|
|
22
|
+
render(): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
|
|
18
23
|
}
|
|
19
24
|
export default ResponsiveTable;
|
package/dist/index.js
CHANGED
|
@@ -29,8 +29,8 @@ function styleInject(css, ref) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
var css_248z = ".ResponsiveTable-module_card__b-U2v {\n border: 1px solid #ccc;\n margin-bottom: 10px;\n border-radius: 8px;\n overflow: hidden;\n box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);\n}\n\n.ResponsiveTable-module_card-header__Ttk51 {\n background-color: #f0f0f0;\n padding: 10px;\n font-weight: bold;\n}\n\n.ResponsiveTable-module_card-body__XIy0h {\n padding: 10px;\n}\n\n/* Apply styles to the table with the specific class 'custom-table' */\n.ResponsiveTable-module_responsiveTable__4y-Od {\n width: 100%;\n border-collapse: collapse;\n margin-bottom: 20px;\n}\n\n.ResponsiveTable-module_responsiveTable__4y-Od thead {\n position: sticky;\n}\n\n/* Style the table header */\n.ResponsiveTable-module_responsiveTable__4y-Od th,\n.ResponsiveTable-module_responsiveTable__4y-Od td {\n padding: 12px;\n text-align: left;\n}\n\n.ResponsiveTable-module_responsiveTable__4y-Od th {\n background-color: #f2f2f2;\n}\n\n/* Alternate row colors */\n.ResponsiveTable-module_responsiveTable__4y-Od tr:nth-child(even) {\n background-color: #f9f9f9;\n}\n\n/* Change background color on hover */\n.ResponsiveTable-module_responsiveTable__4y-Od tr:hover {\n background-color: #d9edf7;\n}\n\n.ResponsiveTable-module_tableContainer__VjWjH {\n overflow-x: auto;\n margin-bottom: 20px;\n}\n";
|
|
33
|
-
var styles = {"card":"ResponsiveTable-module_card__b-U2v","card-header":"ResponsiveTable-module_card-header__Ttk51","card-body":"ResponsiveTable-module_card-body__XIy0h","responsiveTable":"ResponsiveTable-module_responsiveTable__4y-Od","tableContainer":"ResponsiveTable-module_tableContainer__VjWjH"};
|
|
32
|
+
var css_248z = ".ResponsiveTable-module_card__b-U2v {\n border: 1px solid #ccc;\n margin-bottom: 10px;\n border-radius: 8px;\n overflow: hidden;\n box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);\n}\n\n.ResponsiveTable-module_card-header__Ttk51 {\n background-color: #f0f0f0;\n padding: 10px;\n font-weight: bold;\n}\n\n.ResponsiveTable-module_card-body__XIy0h {\n padding: 10px;\n}\n\n/* Apply styles to the table with the specific class 'custom-table' */\n.ResponsiveTable-module_responsiveTable__4y-Od {\n width: 100%;\n border-collapse: collapse;\n margin-bottom: 20px;\n}\n\n.ResponsiveTable-module_responsiveTable__4y-Od thead {\n position: sticky;\n}\n\n/* Style the table header */\n.ResponsiveTable-module_responsiveTable__4y-Od th,\n.ResponsiveTable-module_responsiveTable__4y-Od td {\n padding: 12px;\n text-align: left;\n}\n\n.ResponsiveTable-module_responsiveTable__4y-Od th {\n background-color: #f2f2f2;\n}\n\n/* Alternate row colors */\n.ResponsiveTable-module_responsiveTable__4y-Od tr:nth-child(even) {\n background-color: #f9f9f9;\n}\n\n/* Change background color on hover */\n.ResponsiveTable-module_responsiveTable__4y-Od tr:hover {\n background-color: #d9edf7;\n}\n\n.ResponsiveTable-module_tableContainer__VjWjH {\n overflow-x: auto;\n margin-bottom: 20px;\n}\n\n.ResponsiveTable-module_noDataWrapper__Rj-k3 {\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100%;\n gap: 10px;\n}\n\n.ResponsiveTable-module_noData__IpwNq {\n text-align: center;\n font-weight: bold;\n color: #ca3333;\n padding: 20px;\n}\n";
|
|
33
|
+
var styles = {"card":"ResponsiveTable-module_card__b-U2v","card-header":"ResponsiveTable-module_card-header__Ttk51","card-body":"ResponsiveTable-module_card-body__XIy0h","responsiveTable":"ResponsiveTable-module_responsiveTable__4y-Od","tableContainer":"ResponsiveTable-module_tableContainer__VjWjH","noDataWrapper":"ResponsiveTable-module_noDataWrapper__Rj-k3","noData":"ResponsiveTable-module_noData__IpwNq"};
|
|
34
34
|
styleInject(css_248z);
|
|
35
35
|
|
|
36
36
|
// Class component
|
|
@@ -46,25 +46,44 @@ class ResponsiveTable extends React.Component {
|
|
|
46
46
|
isMobile: false,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
+
get data() {
|
|
50
|
+
if (Array.isArray(this.props.data) && this.props.data.length === 0) {
|
|
51
|
+
return this.props.data;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
get noDataSvg() {
|
|
58
|
+
return (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "#ccc", height: "100", width: "100", viewBox: "0 0 24 24" },
|
|
59
|
+
React.createElement("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-14h2v6h-2zm0 8h2v2h-2z" })));
|
|
60
|
+
}
|
|
61
|
+
get hasData() {
|
|
62
|
+
return this.data.length > 0;
|
|
63
|
+
}
|
|
64
|
+
get noDataComponent() {
|
|
65
|
+
return this.props.noDataComponent || React.createElement("div", { className: styles.noData }, "No data");
|
|
66
|
+
}
|
|
49
67
|
componentDidMount() {
|
|
50
68
|
this.setState(() => {
|
|
51
69
|
return { isMobile: window.innerWidth <= 600 };
|
|
52
70
|
});
|
|
53
|
-
window.addEventListener(
|
|
71
|
+
window.addEventListener('resize', this.handleResize);
|
|
54
72
|
}
|
|
55
73
|
componentWillUnmount() {
|
|
56
|
-
window.removeEventListener(
|
|
74
|
+
window.removeEventListener('resize', this.handleResize);
|
|
57
75
|
}
|
|
58
76
|
getColumnDefinition(columnDefinition, rowIndex) {
|
|
59
|
-
return columnDefinition instanceof Function
|
|
60
|
-
? columnDefinition(this.props.data[0], rowIndex)
|
|
61
|
-
: columnDefinition;
|
|
77
|
+
return columnDefinition instanceof Function ? columnDefinition(this.props.data[0], rowIndex) : columnDefinition;
|
|
62
78
|
}
|
|
63
79
|
render() {
|
|
80
|
+
if (!this.hasData) {
|
|
81
|
+
return this.noDataComponent;
|
|
82
|
+
}
|
|
64
83
|
if (this.state.isMobile) {
|
|
65
|
-
return (React.createElement("div", null, this.props.data.map((row, rowIndex) => (React.createElement("div", { key: rowIndex, className: styles[
|
|
66
|
-
React.createElement("div", { className: styles[
|
|
67
|
-
React.createElement("div", { className: styles[
|
|
84
|
+
return (React.createElement("div", null, this.props.data.map((row, rowIndex) => (React.createElement("div", { key: rowIndex, className: styles['card'] },
|
|
85
|
+
React.createElement("div", { className: styles['card-header'] }, " "),
|
|
86
|
+
React.createElement("div", { className: styles['card-body'] }, this.props.columnDefinitions.map((columnDefinition, colIndex) => {
|
|
68
87
|
const colDef = this.getColumnDefinition(columnDefinition, rowIndex);
|
|
69
88
|
return (React.createElement("div", { key: colIndex },
|
|
70
89
|
React.createElement("p", null,
|
|
@@ -76,7 +95,7 @@ class ResponsiveTable extends React.Component {
|
|
|
76
95
|
})))))));
|
|
77
96
|
}
|
|
78
97
|
return (React.createElement("div", { className: styles.tableContainer },
|
|
79
|
-
React.createElement("table", { className: styles[
|
|
98
|
+
React.createElement("table", { className: styles['responsiveTable'] },
|
|
80
99
|
React.createElement("thead", null,
|
|
81
100
|
React.createElement("tr", null, this.props.columnDefinitions.map((columnDefinition, colIndex) => (React.createElement("th", { key: colIndex }, this.getColumnDefinition(columnDefinition, 0).displayLabel))))),
|
|
82
101
|
React.createElement("tbody", null, this.props.data.map((row, rowIndex) => (React.createElement("tr", { key: rowIndex }, this.props.columnDefinitions.map((columnDefinition, colIndex) => (React.createElement("td", { key: colIndex }, this.getColumnDefinition(columnDefinition, rowIndex).cellRenderer(row)))))))))));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../node_modules/style-inject/dist/style-inject.es.js","../src/UI/ResponsiveTable.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n",null],"names":["Component"],"mappings":";;;;AAAA,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;AAC/B,EAAE,KAAK,GAAG,KAAK,KAAK,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC;AACjC,EAAE,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAC9B;AACA,EAAE,IAAI,CAAC,GAAG,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,EAAE,OAAO,EAAE;AAC1D;AACA,EAAE,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AACvE,EAAE,IAAI,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AAC9C,EAAE,KAAK,CAAC,IAAI,GAAG,UAAU,CAAC;AAC1B;AACA,EAAE,IAAI,QAAQ,KAAK,KAAK,EAAE;AAC1B,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;AACzB,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AAChD,KAAK,MAAM;AACX,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC9B,KAAK;AACL,GAAG,MAAM;AACT,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,GAAG;AACH;AACA,EAAE,IAAI,KAAK,CAAC,UAAU,EAAE;AACxB,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,GAAG,GAAG,CAAC;AACnC,GAAG,MAAM;AACT,IAAI,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;AACpD,GAAG;AACH;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../node_modules/style-inject/dist/style-inject.es.js","../src/UI/ResponsiveTable.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n",null],"names":["Component"],"mappings":";;;;AAAA,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;AAC/B,EAAE,KAAK,GAAG,KAAK,KAAK,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC;AACjC,EAAE,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAC9B;AACA,EAAE,IAAI,CAAC,GAAG,IAAI,OAAO,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+52,18 @@
|
|
|
52
52
|
overflow-x: auto;
|
|
53
53
|
margin-bottom: 20px;
|
|
54
54
|
}
|
|
55
|
+
|
|
56
|
+
.noDataWrapper {
|
|
57
|
+
display: flex;
|
|
58
|
+
justify-content: center;
|
|
59
|
+
align-items: center;
|
|
60
|
+
height: 100%;
|
|
61
|
+
gap: 10px;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.noData {
|
|
65
|
+
text-align: center;
|
|
66
|
+
font-weight: bold;
|
|
67
|
+
color: #ca3333;
|
|
68
|
+
padding: 20px;
|
|
69
|
+
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import React, { Component } from
|
|
2
|
-
import styles from
|
|
3
|
-
import IResponsiveTableColumnDefinition from
|
|
1
|
+
import React, { Component, ReactNode } from 'react';
|
|
2
|
+
import styles from '../Styles/ResponsiveTable.module.css';
|
|
3
|
+
import IResponsiveTableColumnDefinition from '../Data/IResponsiveTableColumnDefinition';
|
|
4
4
|
|
|
5
5
|
type ColumnDefinition<TData> =
|
|
6
6
|
| IResponsiveTableColumnDefinition<TData>
|
|
7
|
-
| ((
|
|
8
|
-
data: TData,
|
|
9
|
-
rowIndex?: number
|
|
10
|
-
) => IResponsiveTableColumnDefinition<TData>);
|
|
7
|
+
| ((data: TData, rowIndex?: number) => IResponsiveTableColumnDefinition<TData>);
|
|
11
8
|
interface IProps<TData> {
|
|
12
9
|
columnDefinitions: ColumnDefinition<TData>[];
|
|
13
10
|
data: TData[];
|
|
11
|
+
noDataComponent?: ReactNode;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
interface IState {
|
|
@@ -26,16 +24,40 @@ class ResponsiveTable<TData> extends Component<IProps<TData>, IState> {
|
|
|
26
24
|
};
|
|
27
25
|
}
|
|
28
26
|
|
|
27
|
+
private get data(): TData[] {
|
|
28
|
+
if (Array.isArray(this.props.data) && this.props.data.length === 0) {
|
|
29
|
+
return this.props.data;
|
|
30
|
+
} else {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private get noDataSvg(): ReactNode {
|
|
36
|
+
return (
|
|
37
|
+
<svg xmlns="http://www.w3.org/2000/svg" fill="#ccc" height="100" width="100" viewBox="0 0 24 24">
|
|
38
|
+
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-14h2v6h-2zm0 8h2v2h-2z" />
|
|
39
|
+
</svg>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private get hasData(): boolean {
|
|
44
|
+
return this.data.length > 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private get noDataComponent(): ReactNode {
|
|
48
|
+
return this.props.noDataComponent || <div className={styles.noData}>No data</div>;
|
|
49
|
+
}
|
|
50
|
+
|
|
29
51
|
componentDidMount(): void {
|
|
30
52
|
this.setState(() => {
|
|
31
53
|
return { isMobile: window.innerWidth <= 600 };
|
|
32
54
|
});
|
|
33
55
|
|
|
34
|
-
window.addEventListener(
|
|
56
|
+
window.addEventListener('resize', this.handleResize);
|
|
35
57
|
}
|
|
36
58
|
|
|
37
59
|
componentWillUnmount(): void {
|
|
38
|
-
window.removeEventListener(
|
|
60
|
+
window.removeEventListener('resize', this.handleResize);
|
|
39
61
|
}
|
|
40
62
|
|
|
41
63
|
handleResize = (): void => {
|
|
@@ -46,39 +68,32 @@ class ResponsiveTable<TData> extends Component<IProps<TData>, IState> {
|
|
|
46
68
|
|
|
47
69
|
private getColumnDefinition(
|
|
48
70
|
columnDefinition: ColumnDefinition<TData>,
|
|
49
|
-
rowIndex: number
|
|
71
|
+
rowIndex: number,
|
|
50
72
|
): IResponsiveTableColumnDefinition<TData> {
|
|
51
|
-
return columnDefinition instanceof Function
|
|
52
|
-
? columnDefinition(this.props.data[0], rowIndex)
|
|
53
|
-
: columnDefinition;
|
|
73
|
+
return columnDefinition instanceof Function ? columnDefinition(this.props.data[0], rowIndex) : columnDefinition;
|
|
54
74
|
}
|
|
55
75
|
|
|
56
76
|
render() {
|
|
77
|
+
if (!this.hasData) {
|
|
78
|
+
return this.noDataComponent;
|
|
79
|
+
}
|
|
57
80
|
if (this.state.isMobile) {
|
|
58
81
|
return (
|
|
59
82
|
<div>
|
|
60
83
|
{this.props.data.map((row, rowIndex) => (
|
|
61
|
-
<div key={rowIndex} className={styles[
|
|
62
|
-
<div className={styles[
|
|
63
|
-
<div className={styles[
|
|
64
|
-
{this.props.columnDefinitions.map(
|
|
65
|
-
(columnDefinition,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
{colDef.displayLabel}:
|
|
75
|
-
</span>{" "}
|
|
76
|
-
{colDef.cellRenderer(row)}
|
|
77
|
-
</p>
|
|
78
|
-
</div>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
)}
|
|
84
|
+
<div key={rowIndex} className={styles['card']}>
|
|
85
|
+
<div className={styles['card-header']}> </div>
|
|
86
|
+
<div className={styles['card-body']}>
|
|
87
|
+
{this.props.columnDefinitions.map((columnDefinition, colIndex) => {
|
|
88
|
+
const colDef = this.getColumnDefinition(columnDefinition, rowIndex);
|
|
89
|
+
return (
|
|
90
|
+
<div key={colIndex}>
|
|
91
|
+
<p>
|
|
92
|
+
<span className="font-bold">{colDef.displayLabel}:</span> {colDef.cellRenderer(row)}
|
|
93
|
+
</p>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
})}
|
|
82
97
|
</div>
|
|
83
98
|
</div>
|
|
84
99
|
))}
|
|
@@ -88,31 +103,20 @@ class ResponsiveTable<TData> extends Component<IProps<TData>, IState> {
|
|
|
88
103
|
|
|
89
104
|
return (
|
|
90
105
|
<div className={styles.tableContainer}>
|
|
91
|
-
<table className={styles[
|
|
106
|
+
<table className={styles['responsiveTable']}>
|
|
92
107
|
<thead>
|
|
93
108
|
<tr>
|
|
94
|
-
{this.props.columnDefinitions.map(
|
|
95
|
-
(columnDefinition,
|
|
96
|
-
|
|
97
|
-
{this.getColumnDefinition(columnDefinition, 0).displayLabel}
|
|
98
|
-
</th>
|
|
99
|
-
)
|
|
100
|
-
)}
|
|
109
|
+
{this.props.columnDefinitions.map((columnDefinition, colIndex) => (
|
|
110
|
+
<th key={colIndex}>{this.getColumnDefinition(columnDefinition, 0).displayLabel}</th>
|
|
111
|
+
))}
|
|
101
112
|
</tr>
|
|
102
113
|
</thead>
|
|
103
114
|
<tbody>
|
|
104
115
|
{this.props.data.map((row, rowIndex) => (
|
|
105
116
|
<tr key={rowIndex}>
|
|
106
|
-
{this.props.columnDefinitions.map(
|
|
107
|
-
(columnDefinition,
|
|
108
|
-
|
|
109
|
-
{this.getColumnDefinition(
|
|
110
|
-
columnDefinition,
|
|
111
|
-
rowIndex
|
|
112
|
-
).cellRenderer(row)}
|
|
113
|
-
</td>
|
|
114
|
-
)
|
|
115
|
-
)}
|
|
117
|
+
{this.props.columnDefinitions.map((columnDefinition, colIndex) => (
|
|
118
|
+
<td key={colIndex}>{this.getColumnDefinition(columnDefinition, rowIndex).cellRenderer(row)}</td>
|
|
119
|
+
))}
|
|
116
120
|
</tr>
|
|
117
121
|
))}
|
|
118
122
|
</tbody>
|