-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.js
executable file
·297 lines (293 loc) · 9.18 KB
/
main.js
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import React from 'react'
import ReactDOM from 'react-dom'
import Reactables from './src/Reactables.jsx'
import Header from './src/components/table/Header.js'
import './main.css'
// let localData = require('./local_data');
let editor = {
ajax: 'http://gigatables.loc/editor.php',
// it is possible to set discrete urls, http methods for any type of request
// ajax: {
// create: {
// url: 'http://gigatables.loc/editor.php',
// type: 'POST',
// headers: {
// 'X-Api-Key': '8013b37216a07f50027139d89ee9f822e3784049'
// }
// },
// edit: {
// url: 'http://gigatables.loc/editor.php',
// type: 'PUT',
// headers: {
// 'X-Api-Key': '8013b37216a07f50027139d89ee9f822e3784049',
// 'X-Header-Key': 'foo-bar'
// }
// },
// delete: {
// url: 'http://gigatables.loc/editor.php',
// type: 'DELETE',
// headers: {
// 'X-Api-Key': '8013b37216a07f50027139d89ee9f822e3784049',
// 'X-Header-Key': 'foo-bar-baz'
// }
// }
// },
ajaxFiles: 'http://gigatables.loc/uploadFiles.php',
struct: {
buttons: ['top', 'bottom'] // buttons
},
fields: [
{
label: 'ID',
name: 'id',
type: 'hidden'
},
{
label: 'Progress',
name: 'field1',
type: 'range',
attrs: {
min: 0,
max: 100
},
// here is the defaultValue passed through attrs because of HTML5 tags
defaultValue: 55
},
{
label: 'Article title:',
name: 'title',
type: 'text', // default, other: password, file, select, multiselect etc
fieldsetOpen: true,
legend: 'Required fields',
attrs: {
pattern: '^[A-Za-z0-9_]+$',
className: 'titleField',
placeholder: 'Place holder'
},
// in regular tags defaultValue passed separately
defaultValue: 'default value'
},
{
label: 'Description:',
name: 'desc',
type: 'textarea',
plugins: 'rte',
attrs: {
className: 'descriptionField'
},
fieldsetClose: true
},
{
label: 'Date Time:',
name: 'date',
type: 'date',
defaultValue: '2018-08-19'
},
{
label: 'Image:',
name: 'image',
type: 'file'
},
{// an example of using select - automatically selected if matches with data in table column
label: 'Types:',
name: 'types[]',
values: [// if select,checkbox,radio etc types - need this pre-set structure of values
{'default': '===========', attrs: {hidden: true, disabled: true}},
{'key1': 'val1'},
{'key2': 'val2'}
],
type: 'select', // select,checkbox,radio
attrs: {required: true},
defaultValue: 'key2'
},
{// an example of using select - automatically selected if matches with data in table column
label: 'Gender:',
name: 'gender',
values: [// if select,checkbox,radio etc types - need this pre-set structure of values
{'male': 'male'},
{'female': 'female'}
],
type: 'checkbox', // select,checkbox,radio
defaultValue: 'male'
},
{
label: 'Cities:',
name: 'cities',
type: 'select',
plugins: 'react-select',
pluginProps: {
options: [
{value: 'msc', label: 'Moscow'},
{value: 'nyc', label: 'New York'},
{value: 'london', label: 'London'}
],
}
}
]
};
let settings = {
struct: {
search: ['top', 'bottom'],
rowsSelector: ['desc', 'top', 'bottom'],
pagination: ['bottom'],
fixedHeader: false, // default false
editableCells: true, // default false
aggregateFooter: true, // default false
download: {
csv: false
},
width: '950px'
},
lang: 'en', // english default
perPageRows: [25, 50, 100, 200],
defaultPerPage: 50,
headers: {
'X-Api-Key': '8013b37216a07f50027139d89ee9f822e3784049',
'X-Header-Key': 'foo-bar'
},
ajax: 'http://gigatables.loc/gigatables.php',
// ajax: new Promise((resolve) => {
// resolve('http://gigatables.loc/gigatables.php')
// }),
// data: localData.data,
// ajaxAutoloadData: true, // default false
// ajaxAutoloadPeriod: 8, // sec
requestType: 'GET',
columns: [
{// include all defaults
data: 'id',
sortable: true, // true by defualt
visible: true, // true by defualt
searchable: true, // true by defualt
discreteSearch: true, // false by default
discreteSearchValue: function (title) {
return 'Search by field - ' + title
}
},
{
data: 'title',
cISearch: true, // default false
footer: 'frequency'
},
{
data: 'desc',
sortable: false,
discreteSearch: true,
discreteCISearch: true // default false
},
{
data: 'date',
searchable: false
},
{
data: 'info'
},
{
data: 'field1',
plugins: 'progressbar',
pluginProps: {
height: 20
}
},
{
data: 'field2',
footer: 'avg'
},
{data: 'field3', visible: false},
{
data: 'consumers',
plugins: 'pie',
pluginProps: {
// ratio: 2,
// startAngle: 3,
// rounded: true,
animate: true
// radius: 33,
}
},
{
data: 'consumers_trend',
plugins: 'trend',
pluginProps: {
autoDraw: true,
autoDrawDuration: 2000,
autoDrawEasing: 'ease-in',
strokeWidth: 15,
padding: 18
}
}
],
columnOpts: [
{
render: (data, row, type) => (
<div>
<form method="post" action="">
<input type="hidden" name="action" value="forms"/>
<input type="hidden" name="id" value={row.id}/>
<div>{data}</div>
</form>
</div>),
target: 'title' // provide data column index to match opts
},
{
render: (data, row, type) => (
<div>
<div>{data}</div>
<div>{(row.id % 2 === 0) ? '**' : '*'}</div>
</div>
),
target: 'date'
}
],
tableOpts: {
buttons: [
// { // reload button to fetch content manually
// extended: 'editor_reload',
// editor: editor,
// triggerAfter: (() => {
// console.log('after reload')
// }), triggerBefore: (() => {
// console.log('before reload')
// })
// },
// {// to set CSV Download button
// extended: "editor_csv",
// editor: editor,
// },
{
extended: 'editor_create', editor: editor, triggerAfter: (function () {
console.log('after create')
}), triggerBefore: (function () {
console.log('before create')
})
},
{
extended: 'editor_edit', editor: editor, triggerBefore: (function () {
console.log('before edit')
})
},
{
extended: 'editor_remove', editor: editor, triggerAfter: (function () {
console.log('after del')
})
}
],
buttonsPosition: ['top', 'bottom'],
theme: 'material-ui' // default std
}
};
ReactDOM.render(
<Reactables editor={editor} settings={settings}>
<Header data="id">ID</Header>
<Header data="title">Name</Header>
<Header data="desc">Description</Header>
<Header data="date">Date</Header>
<Header data="info">Info</Header>
<Header data="field2">Field123 but data from field2</Header>
<Header data="field1">Field1</Header>
<Header data="field3">Field3 invisible</Header>
<Header data="consumers">Consumers</Header>
<Header data="consumers_trend">Consumers trend</Header>
<Header>Field4 invisible</Header>
</Reactables>,
document.getElementById('app'))