-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
115 lines (106 loc) · 2.36 KB
/
App.tsx
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
import React, {useEffect, useState} from 'react';
import DuckTable from '../src';
type Item = {
id: number,
description: string,
value: number,
store: string,
date: string
}
type Results = {
start: number,
end: number,
total: number
}
export const App = (): JSX.Element => {
const [data, setData] = useState<object[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const actions = (_cell: any, row: object, index: number) => {
return <span>Custom</span>;
};
const columns = [{
header: 'ID',
value: 'id',
hide: true
}, {
header: 'Description',
value: 'description',
}, {
header: 'Value',
value: 'value',
}, {
header: 'Store',
value: 'store',
}, {
header: 'Date',
value: 'date',
}, {
header: 'Actions',
value: '',
formatter: actions,
headerAlign: 'center',
classNameRow: 'class-row',
styleHeader: { width: 150 },
classNameHeader: 'class-column',
attrsRow: { 'data-row': 'row' },
styleRow: { backgroundColor: '#d5d5d5' },
attrsHeader: { 'data-header': 'header' }
}];
useEffect(() => {
let rows = 10000;
let arr: Item[] = [];
const add = () => {
let item: Item = {
id: 0,
value: 0,
store: 'Apple',
date: '12/11/2002',
description: 'Iphone'
};
for(let i = 1; i <= rows; i++) {
arr.push({ ...item, id: i, value: i });
if(i === rows) setLoading(false);
}
setData(arr);
}
add();
// setTimeout(() => {
// rows = 4000;
// arr = [];
// add();
// }, 5000);
// change data in real time
},[]);
return (
<DuckTable
data={data}
columns={columns}
/* Optional */
/* -------- */
// sort
sortData
// limits
maxRows={15}
maxPagination={5}
// themes
loading={loading}
themeTable='light'
themeLoader='default'
colorActivePage={'red'}
// Pagination
textNext={'Next'}
textPrevious={'Previous'}
textFullNext={'Full next'}
textFullPrevious={'Full previous'}
// Messages
emptyDataMessage={() => <span>My message.</span>} // jsx or text
showResultsMessage={({ start, end, total }: Results) => ( // jsx or text
<span style={{ color: 'gray' }}>My results</span>
)}
// Events
onClickRow={(e: object, row: object, index: number) => console.log(e, row, index)}
onDoubleClickRow={(e: object, row: object, index: number) => console.log(e, row, index)}
/* -------- */
/>
);
}