aio-table 6.3.1 → 7.0.1

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.
Files changed (3) hide show
  1. package/index.css +31 -9
  2. package/index.js +956 -896
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -23,7 +23,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
23
23
 
24
24
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
25
 
26
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
26
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
27
27
 
28
28
  var AioTableContext = /*#__PURE__*/(0, _react.createContext)();
29
29
 
@@ -33,44 +33,29 @@ class AIOTable extends _react.Component {
33
33
  this.fn = new ATFN({
34
34
  getProps: () => this.props,
35
35
  getState: () => this.state,
36
- setState: obj => this.setState(obj)
36
+ setState: (obj, caller) => this.SetState(obj, caller),
37
+ getContext: () => this.context
37
38
  });
38
39
  let touch = ('ontouchstart' in document.documentElement);
39
40
  this.dom = /*#__PURE__*/(0, _react.createRef)();
40
41
  var {
41
42
  freezeSize,
42
- sorts,
43
43
  paging,
44
44
  columns,
45
- groups
45
+ groups = []
46
46
  } = this.props;
47
47
  let cardRowCount = this.fn.getCardRowCount();
48
- let openDictionary = this.fn.getOpenDictionary(),
49
- groupDictionary = this.fn.getGroupDictionaty();
50
- this.fn.handleOutsideClick();
48
+ let openDictionary = this.fn.getOpenDictionary();
51
49
  let copiedColumns = [...columns];
52
50
  this.state = {
53
51
  touch,
54
52
  openDictionary,
55
53
  cardRowCount,
56
54
  groups,
57
- filterDictionary: {},
58
55
  groupsOpen: {},
59
56
  searchText: '',
60
- addedSorts: [],
61
57
  freezeSize,
62
- groupDictionary,
63
58
  startIndex: 0,
64
- //بخاطر شرایط خاص سورتس باید کاملا از پروپس ورودی ایموتیبل شود//
65
- sorts: sorts.map(o => {
66
- let res = {};
67
-
68
- for (let prop in o) {
69
- res[prop] = o[prop];
70
- }
71
-
72
- return res;
73
- }),
74
59
  //make imutable to prevent change of props.paging because that will compaire with next input props.paging
75
60
  paging: paging ? { ...paging
76
61
  } : false,
@@ -78,56 +63,8 @@ class AIOTable extends _react.Component {
78
63
  columns: copiedColumns,
79
64
  prevColumns: JSON.stringify(copiedColumns),
80
65
  focused: false,
81
- toggleAllState: true,
82
- getCellValue: (row, getValue, field) => {
83
- try {
84
- if (typeof getValue === 'function') {
85
- return getValue(row);
86
- }
87
-
88
- if (field) {
89
- let result;
90
- eval('result = row.' + field);
91
- return result;
92
- }
93
-
94
- return;
95
- } catch {
96
- return;
97
- }
98
- },
99
- setCellValue: (row, field, value) => {
100
- //row is used in eval
101
- let {
102
- model
103
- } = this.props;
104
- eval('row.' + field + ' = ' + value);
105
- return model;
106
- }
107
- };
108
- console.log('in table', this.state.sorts);
109
- }
110
-
111
- copyJson(j) {
112
- let a = o => {
113
- if (Array.isArray(o)) {
114
- return o.map(o => a(o));
115
- }
116
-
117
- if (typeof o === 'object') {
118
- let r = {};
119
-
120
- for (let prop in o) {
121
- r[prop] = a(o[prop]);
122
- }
123
-
124
- return r;
125
- }
126
-
127
- return o;
66
+ toggleAllState: true
128
67
  };
129
-
130
- return a(j);
131
68
  }
132
69
 
133
70
  resizeDown(e) {
@@ -175,25 +112,32 @@ class AIOTable extends _react.Component {
175
112
  });
176
113
  }
177
114
 
178
- getTable(Toolbar) {
179
- var {
115
+ getTable({
116
+ sorts,
117
+ freezeColumns,
118
+ unFreezeColumns,
119
+ columns
120
+ }) {
121
+ let {
180
122
  freezeSize
181
123
  } = this.state;
182
- var rows = this.getRows();
124
+ let {
125
+ cardTemplate
126
+ } = this.props;
127
+ let freezeMode = freezeColumns.length !== 0 && unFreezeColumns.length !== 0;
128
+ let rows = this.getRows(sorts, freezeMode);
183
129
  this.rows = rows;
184
- let freezeMode = this.columnDetails.freeze.active;
185
130
  return /*#__PURE__*/_react.default.createElement("div", {
186
- className: 'aio-table-body',
187
- style: this.fn.getBodyStyle(Toolbar)
188
- }, !freezeMode && /*#__PURE__*/_react.default.createElement(AIOTableUnit, {
131
+ className: 'aio-table-body'
132
+ }, !freezeMode && columns.length !== 0 && /*#__PURE__*/_react.default.createElement(AIOTableUnit, {
189
133
  rows: rows,
190
- columns: this.columnDetails.visibleColumns,
134
+ columns: columns,
191
135
  type: "cells"
192
136
  }), freezeMode && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(AIOTableUnit, {
193
137
  key: 0,
194
138
  id: "aio-table-first-split",
195
139
  rows: rows,
196
- columns: this.columnDetails.freeze.freezeColumns,
140
+ columns: freezeColumns,
197
141
  tableIndex: 0,
198
142
  type: "freezeCells",
199
143
  style: {
@@ -207,13 +151,15 @@ class AIOTable extends _react.Component {
207
151
  key: 1,
208
152
  id: "aio-table-second-split",
209
153
  rows: rows,
210
- columns: this.columnDetails.freeze.unFreezeColumns,
154
+ columns: unFreezeColumns,
211
155
  tableIndex: 1,
212
156
  type: "unFreezeCells"
213
- })));
157
+ })), cardTemplate && /*#__PURE__*/_react.default.createElement(AIOTableUnit, {
158
+ rows: rows
159
+ }));
214
160
  }
215
161
 
216
- getRows() {
162
+ getRows(sorts, freezeMode) {
217
163
  var {
218
164
  model
219
165
  } = this.props;
@@ -222,141 +168,33 @@ class AIOTable extends _react.Component {
222
168
  return false;
223
169
  }
224
170
 
171
+ let {
172
+ groups
173
+ } = this.state;
225
174
  this.index = {
226
175
  render: 0,
227
176
  real: 0
228
177
  };
229
178
  let rows;
230
179
  rows = this.fn.getRowsNested([...model], '_childs');
231
- rows = this.fn.getRowsBySort(rows, this.sorts);
232
- rows = this.fn.getRows(rows, this.columnDetails);
180
+ rows = this.fn.getRowsBySort(rows, sorts.filter(({
181
+ active = true
182
+ }) => active));
183
+ rows = this.fn.getRows(rows, freezeMode);
233
184
  rows = this.fn.getRootsByPaging(rows, this.index);
234
- rows = this.fn.getRootsByGroup(rows, this.groups);
185
+ rows = this.fn.getRootsByGroup(rows, groups.filter(({
186
+ active = true
187
+ }) => active));
235
188
  return this.fn.getRowsByRoots(rows);
236
189
  }
237
190
 
238
- updateColumns() {
239
- var {
240
- search,
241
- translate,
242
- cardTemplate,
243
- toggleAll = false,
244
- toolbarItems = []
245
- } = this.props;
246
- var {
247
- columns
248
- } = this.state;
249
- this.columnDetails = {
250
- freeze: {
251
- active: false,
252
- freezeColumns: [],
253
- unFreezeColumns: []
254
- },
255
- visibleColumns: []
256
- };
257
- this.toolbar = {
258
- show: toggleAll === true || toolbarItems.length > 0,
259
- toggle: [{
260
- text: translate('Show Columns')
261
- }],
262
- toggleAll: toggleAll ? () => this.setState(this.fn.getStateByToggleAll(this.rows)) : false,
263
- freeze: [{
264
- text: translate('Freeze')
265
- }],
266
- groupBy: [{
267
- text: translate('Group By')
268
- }],
269
- sort: [{
270
- text: translate('Sort')
271
- }],
272
- excelColumns: [],
273
- searchColumnIndex: false,
274
- search
275
- };
276
- this.sorts = this.fn.getSorts(this.toolbar);
277
- this.groups = this.fn.getGroups(this.toolbar);
278
-
279
- if (search) {
280
- this.toolbar.show = true;
281
- }
282
-
283
- if (cardTemplate) {
284
- return;
285
- }
286
-
287
- for (let i = 0; i < columns.length; i++) {
288
- let column = columns[i];
289
- column._index = i;
290
- this.fn.setColumnByStorage(column);
291
-
292
- if (column.show && this.fn.showColumnRelativeGroups(column)) {
293
- this.columnDetails.visibleColumns.push(column);
294
-
295
- if (column.excel) {
296
- this.toolbar.excelColumns.push(column);
297
- this.toolbar.show = true;
298
- }
299
-
300
- this.fn.getFreezes(i, this.columnDetails, this.toolbar);
301
- }
302
-
303
- if (column.toggleShow) {
304
- this.fn.getToggleShows(i, this.toolbar);
305
- }
306
-
307
- if (column.search) {
308
- this.toolbar.show = true;
309
- this.toolbar.searchColumnIndex = column._index;
310
- }
311
- }
312
-
313
- if (this.columnDetails.freeze.freezeColumns.length === 0 || this.columnDetails.freeze.unFreezeColumns.length === 0) {
314
- this.columnDetails.freeze.active = false;
315
- }
316
- }
317
-
318
- onChangeFilter(obj) {
319
- var {
320
- onChangeFilter
321
- } = this.props;
322
- var {
323
- columns
324
- } = this.state;
325
- var filters = [];
326
-
327
- for (let prop in obj) {
328
- if (obj[prop].items.length) {
329
- filters.push({
330
- column: columns[prop],
331
- ...obj[prop]
332
- });
333
- }
334
- }
335
-
336
- onChangeFilter(filters);
337
- }
338
-
339
191
  handleIncomingProps() {
340
192
  let {
341
- columns,
342
193
  paging
343
194
  } = this.props;
344
195
  let {
345
- prevColumns,
346
196
  prevPaging
347
197
  } = this.state;
348
- let c = JSON.stringify(columns);
349
-
350
- if (c !== prevColumns) {
351
- setTimeout(() => this.setState({
352
- columns: columns.map(o => {
353
- return { ...o
354
- };
355
- }),
356
- prevColumns: JSON.stringify(columns)
357
- }), 0);
358
- }
359
-
360
198
  let p = JSON.stringify(paging);
361
199
 
362
200
  if (p !== prevPaging) {
@@ -368,6 +206,17 @@ class AIOTable extends _react.Component {
368
206
  }
369
207
  }
370
208
 
209
+ getCellAttrs(row, column) {
210
+ let {
211
+ cellAttrs = {}
212
+ } = column;
213
+ return (typeof cellAttrs === 'function' ? cellAttrs(row) : cellAttrs) || {};
214
+ }
215
+
216
+ SetState(obj, caller) {
217
+ this.setState(obj);
218
+ }
219
+
371
220
  render() {
372
221
  this.handleIncomingProps();
373
222
  var {
@@ -381,13 +230,10 @@ class AIOTable extends _react.Component {
381
230
  style,
382
231
  attrs = {},
383
232
  cardTemplate,
384
- onChangeFilter,
385
233
  onSwap,
386
- padding,
387
234
  translate
388
235
  } = this.props;
389
236
  var {
390
- columns,
391
237
  paging
392
238
  } = this.state;
393
239
  this.rh = rowHeight;
@@ -395,11 +241,10 @@ class AIOTable extends _react.Component {
395
241
  this.th = toolbarHeight;
396
242
  this.rg = rowGap;
397
243
  this.cg = columnGap;
398
- this.updateColumns();
399
- var Toolbar = this.toolbar.show ? /*#__PURE__*/_react.default.createElement(AIOTableToolbar, this.toolbar) : null;
400
- var table = columns ? this.getTable(Toolbar) : '';
244
+ let details = this.fn.getDetails();
401
245
  var context = { ...this.props,
402
246
  ...this.state,
247
+ details,
403
248
  onDrag: obj => this.dragStart = obj,
404
249
  onDrop: obj => {
405
250
  if (!this.dragStart) {
@@ -424,23 +269,23 @@ class AIOTable extends _react.Component {
424
269
  onSwap(this.dragStart, obj);
425
270
  }
426
271
  },
427
- onChangeFilter: onChangeFilter ? this.onChangeFilter.bind(this) : undefined,
428
- SetState: obj => this.setState(obj),
272
+ SetState: this.SetState.bind(this),
429
273
  onScroll: index => this.fn.onScroll(this.dom, index),
430
- groups: this.groups,
274
+ getCellAttrs: this.getCellAttrs.bind(this),
431
275
  fn: this.fn,
432
276
  rows: this.rows
433
277
  };
278
+ this.context = context;
279
+ let table = this.getTable(details);
434
280
  return /*#__PURE__*/_react.default.createElement(AioTableContext.Provider, {
435
281
  value: context
436
282
  }, /*#__PURE__*/_react.default.createElement("div", _extends({
437
283
  className: 'aio-table' + (className ? ' ' + className : '') + (rtl ? ' rtl' : ''),
438
284
  tabIndex: 0,
439
285
  ref: this.dom,
440
- style: { ...style,
441
- padding
286
+ style: { ...style
442
287
  }
443
- }, attrs), Toolbar, !cardTemplate && this.columnDetails.visibleColumns.length === 0 && this.fn.getLoading(), table, paging && /*#__PURE__*/_react.default.createElement(AIOTablePaging, {
288
+ }, attrs), /*#__PURE__*/_react.default.createElement(AIOTableToolbar, details), table, paging && /*#__PURE__*/_react.default.createElement(AIOTablePaging, {
444
289
  rtl: rtl,
445
290
  translate: translate,
446
291
  paging: paging,
@@ -461,15 +306,11 @@ class AIOTable extends _react.Component {
461
306
  exports.default = AIOTable;
462
307
  AIOTable.defaultProps = {
463
308
  columns: [],
464
- headerHeight: 36,
465
- rowHeight: 36,
466
309
  toolbarHeight: 36,
467
310
  rowGap: 6,
468
- padding: 12,
469
- indent: 20,
311
+ indent: 16,
470
312
  translate: text => text,
471
313
  freezeSize: 300,
472
- sorts: [],
473
314
  groups: []
474
315
  };
475
316
 
@@ -487,52 +328,23 @@ class AIOTableToolbar extends _react.Component {
487
328
  this.setState({
488
329
  searchText: value
489
330
  });
490
- this.searchTimeout = setTimeout(() => {
491
- let {
492
- SetState
493
- } = this.context;
494
- let {
495
- search
496
- } = this.props;
497
-
498
- if (search) {
499
- SetState({
500
- searchText: value
501
- });
502
- } else {
503
- let {
504
- filterDictionary
505
- } = this.context;
506
- let {
507
- searchColumnIndex
508
- } = this.props;
509
- filterDictionary[searchColumnIndex] = {
510
- items: value ? [{
511
- operator: 'contain',
512
- value
513
- }] : [],
514
- booleanType: 'or'
515
- };
516
- SetState({
517
- filterDictionary
518
- });
519
- }
520
- }, time);
331
+ this.searchTimeout = setTimeout(() => this.context.SetState({
332
+ searchText: value
333
+ }), time);
521
334
  }
522
335
 
523
336
  getSearch() {
524
- var {
337
+ let {
525
338
  translate
526
339
  } = this.context;
527
- var {
528
- searchText
529
- } = this.state;
530
- var {
531
- searchColumnIndex,
340
+ let {
532
341
  search
533
342
  } = this.props;
343
+ let {
344
+ searchText
345
+ } = this.state;
534
346
 
535
- if (typeof searchColumnIndex !== 'number' && !search) {
347
+ if (!search) {
536
348
  return /*#__PURE__*/_react.default.createElement("div", {
537
349
  style: {
538
350
  flex: 1
@@ -562,110 +374,136 @@ class AIOTableToolbar extends _react.Component {
562
374
  }
563
375
 
564
376
  render() {
565
- var {
377
+ let {
566
378
  fn,
567
379
  rows,
568
380
  translate,
569
381
  rtl,
570
382
  toggleAllState,
571
- padding,
572
383
  toolbarItems = [],
573
384
  SetState,
574
- toolbarStyle = {}
575
- } = this.context;
576
- var {
577
- toggle,
578
- freeze,
579
- groupBy,
580
- sort,
385
+ toolbarAttrs = {},
581
386
  toggleAll,
582
- excelColumns
387
+ groups
388
+ } = this.context;
389
+ let {
390
+ toggleOptions,
391
+ freezeOptions,
392
+ groupOptions,
393
+ excelColumns,
394
+ sortOptions
583
395
  } = this.props;
584
- var buttonProps = {
396
+ let buttonProps = {
585
397
  type: 'select',
586
- caret: false,
587
398
  rtl,
399
+ caret: false,
588
400
  className: 'aio-table-toolbar-button',
589
- animate: true
401
+ animate: true,
402
+ popupAttrs: {
403
+ style: {
404
+ maxHeight: 500
405
+ }
406
+ }
590
407
  };
591
- let iconSize = 0.7;
408
+ let Sort, Toggle, Group, Freeze, Excel, ToggleAll;
409
+
410
+ if (sortOptions.length) {
411
+ let title = translate('Sort');
412
+ let props = { ...buttonProps,
413
+ options: sortOptions,
414
+ title,
415
+ key: 'sort',
416
+ text: aioTableGetSvg('sort'),
417
+ popupHeader: /*#__PURE__*/_react.default.createElement("div", {
418
+ className: "aio-table-popup-header"
419
+ }, title)
420
+ };
421
+ Sort = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
422
+ }
423
+
424
+ if (toggleOptions.length) {
425
+ let title = translate('Show Columns');
426
+ let props = { ...buttonProps,
427
+ options: toggleOptions,
428
+ title,
429
+ key: 'toggle',
430
+ text: aioTableGetSvg('eye'),
431
+ popupHeader: /*#__PURE__*/_react.default.createElement("div", {
432
+ className: "aio-table-popup-header"
433
+ }, title)
434
+ };
435
+ Toggle = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
436
+ }
437
+
438
+ if (groupOptions.length) {
439
+ let title = translate('Group By');
440
+ let props = { ...buttonProps,
441
+ options: groupOptions,
442
+ title,
443
+ key: 'group',
444
+ text: aioTableGetSvg('group', {
445
+ flip: rtl === true
446
+ }),
447
+ popupHeader: /*#__PURE__*/_react.default.createElement("div", {
448
+ className: "aio-table-popup-header"
449
+ }, title),
450
+ onSwap: (start, end, swap) => SetState({
451
+ groups: swap(groups, start, end)
452
+ })
453
+ };
454
+ Group = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
455
+ }
456
+
457
+ if (freezeOptions.length) {
458
+ let title = translate('Freeze');
459
+ let props = { ...buttonProps,
460
+ options: freezeOptions,
461
+ title,
462
+ key: 'freeze',
463
+ text: aioTableGetSvg('freeze'),
464
+ popupHeader: /*#__PURE__*/_react.default.createElement("div", {
465
+ className: "aio-table-popup-header"
466
+ }, title)
467
+ };
468
+ Freeze = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
469
+ }
470
+
471
+ if (toggleAll) {
472
+ let title = translate('Toggle All');
473
+ let props = { ...buttonProps,
474
+ title,
475
+ key: 'toggleAll',
476
+ type: 'button',
477
+ text: !toggleAllState ? aioTableGetSvg('toggleAllMinus') : aioTableGetSvg('toggleAllPlus'),
478
+ onclick: () => SetState(fn.getStateByToggleAll(rows))
479
+ };
480
+ ToggleAll = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
481
+ }
482
+
483
+ if (excelColumns.length) {
484
+ let title = translate('Export To Excel');
485
+ let props = { ...buttonProps,
486
+ title,
487
+ key: 'excel',
488
+ type: 'button',
489
+ text: aioTableGetSvg('excel'),
490
+ onClick: () => fn.exportToExcel(excelColumns, rows)
491
+ };
492
+ Excel = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
493
+ }
494
+
592
495
  return /*#__PURE__*/_react.default.createElement("div", {
593
- className: "aio-table-toolbar",
594
- style: {
595
- marginBottom: padding,
596
- ...toolbarStyle
496
+ className: 'aio-table-toolbar' + (toolbarAttrs.className ? ' ' + toolbarAttrs.className : ''),
497
+ style: { ...toolbarAttrs.style
597
498
  }
598
- }, toggleAll !== false && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
599
- key: "toggleAll"
600
- }, buttonProps, {
601
- type: "button",
602
- title: translate('Toggle All'),
603
- onClick: () => toggleAll(),
604
- text: !toggleAllState ? aioTableGetSvg('toggleAllMinus') : aioTableGetSvg('toggleAllPlus')
605
- })), excelColumns.length > 0 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
606
- key: "excel"
607
- }, buttonProps, {
608
- type: "button",
609
- title: translate('Export To Excel'),
610
- onClick: () => {
611
- fn.exportToExcel(excelColumns, rows);
612
- },
613
- text: aioTableGetSvg('excel')
614
- })), toolbarItems.map((o, i) => /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
499
+ }, ToggleAll, Excel, toolbarItems.map((o, i) => /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
615
500
  type: "button",
616
501
  rtl: rtl,
617
502
  className: "aio-table-toolbar-button",
618
503
  animate: true
619
504
  }, o, {
620
505
  key: 'ti' + i
621
- }))), this.getSearch(), groupBy.length > 1 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
622
- key: "groupby"
623
- }, buttonProps, {
624
- options: groupBy,
625
- title: translate('Group By'),
626
- text: aioTableGetSvg('group', {
627
- flip: rtl === true
628
- }),
629
- onSwap: (start, end, swap) => {
630
- let {
631
- groups
632
- } = this.context;
633
- SetState({
634
- groups: swap(groups, start - 1, end - 1)
635
- });
636
- }
637
- })), sort.length > 1 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
638
- key: "sort"
639
- }, buttonProps, {
640
- options: sort,
641
- title: translate('Sort'),
642
- text: aioTableGetSvg('sort'),
643
- onSwap: (start, end, swap) => {
644
- let {
645
- sorts
646
- } = this.context;
647
- SetState({
648
- sorts: swap(sorts, start - 1, end - 1)
649
- }); //-1 because title of items added to options[0]
650
- }
651
- })), toggle.length > 1 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
652
- key: "toggle"
653
- }, buttonProps, {
654
- text: aioTableGetSvg('eye'),
655
- options: toggle,
656
- title: translate('Show Columns'),
657
- popupStyle: {
658
- maxHeight: 400
659
- }
660
- })), freeze.length > 1 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
661
- key: "freeze"
662
- }, buttonProps, {
663
- text: aioTableGetSvg('freeze', {
664
- flip: rtl === true
665
- }),
666
- options: freeze,
667
- title: translate('Freeze Columns')
668
- })));
506
+ }))), this.getSearch(), Group, Sort, Toggle, Freeze);
669
507
  }
670
508
 
671
509
  }
@@ -784,7 +622,26 @@ class AIOTableUnit extends _react.Component {
784
622
  this.dom = /*#__PURE__*/(0, _react.createRef)();
785
623
  }
786
624
 
625
+ getCardStyle() {
626
+ let {
627
+ columnGap,
628
+ rowGap
629
+ } = this.context;
630
+ return {
631
+ gridColumnGap: columnGap,
632
+ gridRowGap: rowGap
633
+ };
634
+ }
635
+
787
636
  getStyle() {
637
+ if (this.context.cardTemplate) {
638
+ return this.getCardStyle();
639
+ }
640
+
641
+ return this.getGridStyle();
642
+ }
643
+
644
+ getGridStyle() {
788
645
  var {
789
646
  rowGap,
790
647
  columnGap
@@ -830,6 +687,7 @@ class AIOTableUnit extends _react.Component {
830
687
  } = this.props;
831
688
  return columns.map((column, i) => {
832
689
  return /*#__PURE__*/_react.default.createElement(AIOTableTitle, {
690
+ isLast: i === columns.length - 1,
833
691
  key: 'title' + i,
834
692
  column: column,
835
693
  gridTemplateColumns: this.gridTemplateColumns,
@@ -876,15 +734,14 @@ class AIOTableUnit extends _react.Component {
876
734
 
877
735
  keyDown(e) {
878
736
  var {
879
- SetState,
880
- focused
737
+ SetState
881
738
  } = this.context;
882
739
 
883
740
  if (e.keyCode === 27) {
884
741
  (0, _jquery.default)('.aio-table-input').blur();
885
742
  SetState({
886
743
  focused: false
887
- });
744
+ }, 'keyDown');
888
745
  } else if ([37, 38, 39, 40].indexOf(e.keyCode) !== -1) {
889
746
  this.arrow(e);
890
747
  }
@@ -971,7 +828,8 @@ class AIOTableUnit extends _react.Component {
971
828
  cardTemplate,
972
829
  cardRowCount,
973
830
  search,
974
- searchText
831
+ searchText,
832
+ indent
975
833
  } = this.context;
976
834
  var {
977
835
  tableIndex,
@@ -1022,7 +880,21 @@ class AIOTableUnit extends _react.Component {
1022
880
  return /*#__PURE__*/_react.default.createElement("div", {
1023
881
  key: rowIndex + '-' + tableIndex,
1024
882
  className: "aio-table-card"
1025
- }, cardTemplate(row.row, () => fn.toggleRow(row.row)));
883
+ }, row.row._level !== 0 && /*#__PURE__*/_react.default.createElement("div", {
884
+ style: {
885
+ width: row.row._level * indent,
886
+ border: '1px solid',
887
+ height: '100%',
888
+ position: 'relative'
889
+ }
890
+ }, /*#__PURE__*/_react.default.createElement("svg", {
891
+ style: {
892
+ background: 'yellow',
893
+ width: '100%',
894
+ positon: 'absolute',
895
+ height: '100%'
896
+ }
897
+ })), cardTemplate(row.row, () => fn.toggleRow(row.row)));
1026
898
  }), rows && rows.length === 0 && fn.getNoData(columns), !rows && fn.getLoading());
1027
899
  }
1028
900
 
@@ -1039,7 +911,8 @@ class AIOTableUnit extends _react.Component {
1039
911
  fn,
1040
912
  focused,
1041
913
  SetState,
1042
- striped
914
+ striped,
915
+ getCellAttrs
1043
916
  } = this.context;
1044
917
  var {
1045
918
  rows,
@@ -1068,7 +941,7 @@ class AIOTableUnit extends _react.Component {
1068
941
  return /*#__PURE__*/_react.default.createElement(AIOTableGroup, {
1069
942
  tableIndex,
1070
943
  row: o,
1071
- columns,
944
+ columns: columns,
1072
945
  key: 'group' + i + '-' + tableIndex
1073
946
  });
1074
947
  }
@@ -1081,13 +954,14 @@ class AIOTableUnit extends _react.Component {
1081
954
  let row = o.row;
1082
955
  let cellId = i + '-' + j + '-' + tableIndex;
1083
956
  let inlineEdit = this.getPropValue(row, column, column.inlineEdit);
957
+ let attrs = getCellAttrs(row, column);
1084
958
  return /*#__PURE__*/_react.default.createElement(AIOTableCell, {
1085
959
  key: cellId,
1086
960
  attrs: {
1087
961
  'data-row-index': this.renderIndex,
1088
- 'data-col-index': column._renderIndex,
962
+ 'data-col-index': column.renderIndex,
1089
963
  'data-real-row-index': row._index,
1090
- 'data-real-col-index': column._index,
964
+ 'data-real-col-index': column.realIndex,
1091
965
  'data-child-index': row._childIndex,
1092
966
  'data-childs-length': row._childsLength,
1093
967
  'data-lavel': row._level,
@@ -1098,13 +972,26 @@ class AIOTableUnit extends _react.Component {
1098
972
  onDragOver: e => e.preventDefault(),
1099
973
  onDragStart: () => onDrag(row),
1100
974
  onClick: () => {
975
+ var {
976
+ focused,
977
+ SetState
978
+ } = this.context;
979
+
980
+ if (attrs.onClick) {
981
+ attrs.onClick(row);
982
+ }
983
+
1101
984
  if (!inlineEdit || focused === cellId) {
1102
985
  return;
1103
986
  }
1104
987
 
988
+ if (focused === false) {
989
+ setTimeout(() => fn.handleOutsideClick(), 5);
990
+ }
991
+
1105
992
  SetState({
1106
993
  focused: cellId
1107
- });
994
+ }, 'cellonClick');
1108
995
  setTimeout(() => (0, _jquery.default)('.aio-table-input:focus').select(), 10);
1109
996
  }
1110
997
  },
@@ -1126,18 +1013,22 @@ class AIOTableUnit extends _react.Component {
1126
1013
  _defineProperty(AIOTableUnit, "contextType", AioTableContext);
1127
1014
 
1128
1015
  class AIOTableTitle extends _react.Component {
1129
- getStyle() {
1016
+ constructor(props) {
1017
+ super(props);
1018
+ this.dom = /*#__PURE__*/(0, _react.createRef)();
1019
+ }
1020
+
1021
+ getStyle(style) {
1130
1022
  let {
1131
1023
  headerHeight,
1132
- columnGap,
1133
- titleStyle = {}
1024
+ columnGap
1134
1025
  } = this.context;
1135
1026
  return {
1136
1027
  height: headerHeight,
1137
1028
  top: 0,
1138
1029
  borderLeft: columnGap ? 'none' : undefined,
1139
1030
  borderRight: columnGap ? 'none' : undefined,
1140
- ...titleStyle
1031
+ ...style
1141
1032
  };
1142
1033
  }
1143
1034
 
@@ -1162,10 +1053,8 @@ class AIOTableTitle extends _react.Component {
1162
1053
  (0, _jquery.default)(window).bind(touch ? 'touchend' : 'mouseup', _jquery.default.proxy(this.resizeUp, this));
1163
1054
  this.resizeDetails = {
1164
1055
  client: fn.getClient(e),
1165
- width: parseInt(gridTemplateColumns[column._renderIndex]),
1166
- renderIndex: column._renderIndex,
1167
- index: column._index,
1168
- minWidth: column.minWidth
1056
+ width: parseInt(gridTemplateColumns[column.renderIndex]),
1057
+ column
1169
1058
  };
1170
1059
  }
1171
1060
 
@@ -1182,19 +1071,18 @@ class AIOTableTitle extends _react.Component {
1182
1071
  var Client = fn.getClient(e);
1183
1072
  var {
1184
1073
  client,
1185
- renderIndex,
1186
1074
  width,
1187
- minWidth = '30px'
1075
+ column
1188
1076
  } = this.resizeDetails;
1189
1077
  var offset = Client[0] - client[0];
1190
1078
  let newWidth = width + offset * (rtl ? -1 : 1);
1191
1079
 
1192
- if (newWidth < parseInt(minWidth)) {
1193
- newWidth = parseInt(minWidth);
1080
+ if (newWidth < parseInt(column.minWidth || 36)) {
1081
+ newWidth = parseInt(column.minWidth || 36);
1194
1082
  }
1195
1083
 
1196
1084
  this.resizeDetails.newWidth = newWidth + 'px';
1197
- gridTemplateColumns[renderIndex] = this.resizeDetails.newWidth;
1085
+ gridTemplateColumns[column.renderIndex] = this.resizeDetails.newWidth;
1198
1086
  setStyle(gridTemplateColumns);
1199
1087
  }
1200
1088
 
@@ -1212,10 +1100,12 @@ class AIOTableTitle extends _react.Component {
1212
1100
  SetState
1213
1101
  } = this.context;
1214
1102
  var {
1215
- index,
1216
1103
  newWidth
1217
1104
  } = this.resizeDetails;
1218
- let column = { ...columns[index],
1105
+ let {
1106
+ column
1107
+ } = this.props;
1108
+ column = { ...column,
1219
1109
  width: newWidth
1220
1110
  };
1221
1111
 
@@ -1228,14 +1118,9 @@ class AIOTableTitle extends _react.Component {
1228
1118
  localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
1229
1119
  }
1230
1120
 
1121
+ columns = columns.map((c, i) => i === column.realIndex ? column : c);
1231
1122
  SetState({
1232
- columns: columns.map((c, i) => {
1233
- if (i === index) {
1234
- return column;
1235
- }
1236
-
1237
- return c;
1238
- })
1123
+ columns
1239
1124
  });
1240
1125
  }
1241
1126
 
@@ -1245,20 +1130,22 @@ class AIOTableTitle extends _react.Component {
1245
1130
  columnGap
1246
1131
  } = this.context;
1247
1132
  var {
1248
- getKeys,
1249
- padding = '36px'
1133
+ template
1250
1134
  } = column;
1251
- var keys = getKeys();
1135
+ let {
1136
+ padding = 36
1137
+ } = template;
1138
+ var keys = template.getKeys();
1252
1139
  return /*#__PURE__*/_react.default.createElement("div", {
1253
1140
  className: "aio-table-title aio-table-title-gantt",
1254
1141
  style: {
1255
- padding: `0 ${padding}`,
1142
+ padding: `0 ${+padding}px`,
1256
1143
  height: headerHeight,
1257
1144
  top: 0,
1258
1145
  borderLeft: columnGap ? 'none' : undefined,
1259
1146
  borderRight: columnGap ? 'none' : undefined
1260
1147
  },
1261
- key: column._index + 'title'
1148
+ key: column.realIndex + 'title'
1262
1149
  }, /*#__PURE__*/_react.default.createElement(_rRangeSlider.default, {
1263
1150
  start: 0,
1264
1151
  end: keys.length - 1,
@@ -1287,20 +1174,31 @@ class AIOTableTitle extends _react.Component {
1287
1174
  column,
1288
1175
  onDragStart,
1289
1176
  onDragOver,
1290
- onDrop
1177
+ onDrop,
1178
+ isLast
1291
1179
  } = this.props;
1180
+ let {
1181
+ rtl
1182
+ } = this.context;
1292
1183
 
1293
- if (column.template === 'gantt') {
1184
+ if (column.template && column.template.type === 'gantt') {
1294
1185
  return this.getGanttTitle(column);
1295
1186
  }
1296
1187
 
1297
1188
  let title = typeof column.title === 'function' ? column.title() : column.title;
1189
+ let attrs = { ...this.context.titleAttrs,
1190
+ ...column.titleAttrs
1191
+ };
1192
+ let dataUniqId = 'aiotabletitle' + Math.round(Math.random() * 10000000);
1298
1193
  return /*#__PURE__*/_react.default.createElement("div", {
1299
- style: this.getStyle(),
1194
+ ref: this.dom,
1195
+ "data-uniq-id": dataUniqId,
1196
+ style: this.getStyle(attrs.style),
1300
1197
  draggable: false,
1301
- className: "aio-table-title"
1198
+ className: 'aio-table-title' + (attrs.className ? ' ' + attrs.className : '') + (isLast ? ' last-child' : '') + (rtl ? ' rtl' : ' ltr')
1302
1199
  }, /*#__PURE__*/_react.default.createElement(AIOTableFilter, {
1303
- column: column
1200
+ column: column,
1201
+ dataUniqId: dataUniqId
1304
1202
  }), /*#__PURE__*/_react.default.createElement("div", {
1305
1203
  className: "aio-table-title-text",
1306
1204
  style: {
@@ -1308,8 +1206,8 @@ class AIOTableTitle extends _react.Component {
1308
1206
  cursor: column.movable === false ? undefined : 'move'
1309
1207
  },
1310
1208
  draggable: column.movable !== false,
1311
- onDragStart: () => onDragStart(column._index),
1312
- onDragOver: e => onDragOver(e, column._index),
1209
+ onDragStart: () => onDragStart(column.realIndex),
1210
+ onDragOver: e => onDragOver(e, column.realIndex),
1313
1211
  onDrop: () => onDrop(column)
1314
1212
  }, title), column.width !== 'auto' && /*#__PURE__*/_react.default.createElement("div", {
1315
1213
  className: "aio-table-resize",
@@ -1327,11 +1225,14 @@ class AIOTableTitle extends _react.Component {
1327
1225
  _defineProperty(AIOTableTitle, "contextType", AioTableContext);
1328
1226
 
1329
1227
  class AIOTableGroup extends _react.Component {
1330
- getStyle(columns) {
1228
+ getStyle() {
1331
1229
  let {
1332
1230
  rowHeight,
1333
1231
  fn
1334
1232
  } = this.context;
1233
+ let {
1234
+ columns
1235
+ } = this.props;
1335
1236
  return { ...fn.getFullCellStyle(columns),
1336
1237
  height: rowHeight
1337
1238
  };
@@ -1373,12 +1274,11 @@ class AIOTableGroup extends _react.Component {
1373
1274
  } = this.context;
1374
1275
  let {
1375
1276
  row,
1376
- tableIndex,
1377
- columns
1277
+ tableIndex
1378
1278
  } = this.props;
1379
1279
  return /*#__PURE__*/_react.default.createElement("div", {
1380
1280
  className: "aio-table-group",
1381
- style: this.getStyle(columns)
1281
+ style: this.getStyle()
1382
1282
  }, tableIndex !== 1 && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
1383
1283
  style: {
1384
1284
  width: indent * row._level,
@@ -1414,39 +1314,50 @@ class AIOTableCell extends _react.Component {
1414
1314
 
1415
1315
  getStyle(column, row) {
1416
1316
  var {
1417
- padding = '36px',
1418
1317
  template,
1419
1318
  minWidth = '30px'
1420
1319
  } = column;
1421
1320
  var {
1422
1321
  rowHeight,
1423
- getCellStyle = () => {
1424
- return {};
1425
- }
1322
+ getCellAttrs
1426
1323
  } = this.context;
1324
+ let {
1325
+ striped
1326
+ } = this.props;
1427
1327
  var style = {
1428
1328
  height: rowHeight,
1429
1329
  overflow: template ? undefined : 'hidden',
1430
1330
  minWidth
1431
1331
  };
1432
1332
 
1433
- if (column.template === 'gantt') {
1434
- style.padding = `0 ${padding}`;
1333
+ if (column.template && column.template.type === 'gantt') {
1334
+ style.padding = 0;
1335
+ }
1336
+
1337
+ if (typeof striped === 'string') {
1338
+ style.background = striped;
1339
+ } else if (Array.isArray(striped)) {
1340
+ style.background = striped[0];
1341
+ style.color = striped[1];
1435
1342
  }
1436
1343
 
1437
- let cellStyle = getCellStyle(row, column);
1344
+ let attrs = getCellAttrs(row, column);
1438
1345
  return { ...style,
1439
- ...cellStyle
1346
+ ...attrs.style
1440
1347
  };
1441
1348
  }
1442
1349
 
1443
1350
  getClassName(row, column) {
1351
+ let {
1352
+ getCellAttrs
1353
+ } = this.context;
1444
1354
  var className = 'aio-table-cell';
1445
1355
  let {
1446
1356
  striped
1447
1357
  } = this.props;
1358
+ let attrs = getCellAttrs(row, column);
1448
1359
 
1449
- if (striped) {
1360
+ if (striped === true) {
1450
1361
  className += ' striped';
1451
1362
  }
1452
1363
 
@@ -1458,8 +1369,8 @@ class AIOTableCell extends _react.Component {
1458
1369
  className += ' aio-table-cell-gantt';
1459
1370
  }
1460
1371
 
1461
- if (column.className) {
1462
- className += ' ' + column.className;
1372
+ if (attrs.className) {
1373
+ className += ' ' + attrs.className;
1463
1374
  }
1464
1375
 
1465
1376
  if (column.inlineEdit) {
@@ -1492,9 +1403,7 @@ class AIOTableCell extends _react.Component {
1492
1403
  } = this.context;
1493
1404
  let icon;
1494
1405
 
1495
- if (!row._childsLength) {
1496
- icon = '';
1497
- } else if (row._opened) {
1406
+ if (row._opened) {
1498
1407
  icon = aioTableGetSvg('chevronDown');
1499
1408
  } else {
1500
1409
  icon = aioTableGetSvg('chevronRight', {
@@ -1504,37 +1413,100 @@ class AIOTableCell extends _react.Component {
1504
1413
 
1505
1414
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
1506
1415
  className: "aio-table-toggle",
1507
- onClick: () => fn.toggleRow(row)
1416
+ onClick: () => fn.toggleRow(row),
1417
+ style: {
1418
+ opacity: row._childsLength ? 1 : 0
1419
+ }
1508
1420
  }, icon), /*#__PURE__*/_react.default.createElement("div", {
1509
1421
  className: "aio-table-cell-gap"
1510
1422
  }));
1511
1423
  }
1512
1424
 
1513
- getContent(row, column, value) {
1514
- var {
1515
- focused,
1516
- fn
1517
- } = this.context;
1425
+ splitNumber(num) {
1426
+ if (!num) {
1427
+ return num;
1428
+ }
1429
+
1430
+ let str = num.toString();
1431
+ let dotIndex = str.indexOf('.');
1432
+
1433
+ if (dotIndex !== -1) {
1434
+ str = str.slice(0, dotIndex);
1435
+ }
1436
+
1437
+ let res = '';
1438
+ let index = 0;
1439
+
1440
+ for (let i = str.length - 1; i >= 0; i--) {
1441
+ res = str[i] + res;
1442
+
1443
+ if (index === 2) {
1444
+ index = 0;
1445
+
1446
+ if (i > 0) {
1447
+ res = ',' + res;
1448
+ }
1449
+ } else {
1450
+ index++;
1451
+ }
1452
+ }
1453
+
1454
+ return res;
1455
+ }
1456
+
1457
+ getContentByTemplate(row, column, value) {
1458
+ let {
1459
+ fn
1460
+ } = this.context;
1461
+ let template = typeof column.template === 'function' ? column.template(row, column) : column.template;
1462
+
1463
+ if (!template) {
1464
+ return value;
1465
+ }
1466
+
1467
+ if (template.type === 'slider') {
1468
+ return fn.getSliderCell(template, value);
1469
+ }
1470
+
1471
+ if (template.type === 'checkbox') {
1472
+ return fn.getCheckboxCell(template, value, row);
1473
+ }
1474
+
1475
+ if (template.type === 'options') {
1476
+ return fn.getOptionsCell(template, row);
1477
+ }
1478
+
1479
+ if (template.type === 'split') {
1480
+ let newValue = this.splitNumber(value);
1481
+
1482
+ if (template.editValue) {
1483
+ newValue = template.editValue(newValue);
1484
+ }
1485
+
1486
+ return newValue;
1487
+ }
1488
+
1489
+ if (template.type === 'gantt') {
1490
+ return fn.getGanttCell(row, template);
1491
+ }
1492
+
1493
+ return template;
1494
+ }
1495
+
1496
+ getContent(row, column, value) {
1497
+ let {
1498
+ focused
1499
+ } = this.context;
1518
1500
  let {
1519
1501
  inlineEdit
1520
1502
  } = this.props;
1503
+ let template = this.getContentByTemplate(row, column, value);
1521
1504
  var content = '';
1522
- let template = typeof column.template === 'function' ? column.template(row, column) : column.template;
1523
1505
 
1524
- if (template && template.type === 'slider') {
1525
- content = fn.getSliderCell(template);
1526
- } else if (template && template.type === 'options') {
1527
- content = fn.getOptionsCell(template);
1528
- } else if (template && template.type === 'gantt') {
1529
- content = fn.getGanttCell(row, template);
1530
- } else if (template && inlineEdit) {
1531
- content = focused ? this.getInput(row, column) : template;
1532
- } else if (template) {
1533
- content = template;
1534
- } else if (inlineEdit) {
1506
+ if (inlineEdit && focused) {
1535
1507
  content = this.getInput(row, column);
1536
1508
  } else {
1537
- content = value;
1509
+ content = template;
1538
1510
  }
1539
1511
 
1540
1512
  if (column.subText) {
@@ -1549,10 +1521,18 @@ class AIOTableCell extends _react.Component {
1549
1521
  return /*#__PURE__*/_react.default.createElement("div", {
1550
1522
  className: "aio-table-cell-has-subtext"
1551
1523
  }, /*#__PURE__*/_react.default.createElement("div", {
1524
+ style: {
1525
+ flex: 1
1526
+ }
1527
+ }), /*#__PURE__*/_react.default.createElement("div", {
1552
1528
  className: "aio-table-cell-uptext"
1553
1529
  }, content), /*#__PURE__*/_react.default.createElement("div", {
1554
1530
  className: "aio-table-cell-subtext"
1555
- }, subText));
1531
+ }, subText), /*#__PURE__*/_react.default.createElement("div", {
1532
+ style: {
1533
+ flex: 1
1534
+ }
1535
+ }));
1556
1536
  }
1557
1537
 
1558
1538
  return content;
@@ -1565,7 +1545,7 @@ class AIOTableCell extends _react.Component {
1565
1545
  inlineEdit
1566
1546
  } = this.props;
1567
1547
  let {
1568
- setCellValue
1548
+ fn
1569
1549
  } = this.context;
1570
1550
  let res;
1571
1551
  this.setState({
@@ -1574,8 +1554,8 @@ class AIOTableCell extends _react.Component {
1574
1554
 
1575
1555
  if (inlineEdit.onChange) {
1576
1556
  res = await inlineEdit.onChange(row, value);
1577
- } else {
1578
- res = await this.context.onChange(setCellValue(row, column.field, value));
1557
+ } else if (typeof column.getValue === 'string') {
1558
+ res = await this.context.onChange(fn.setCellValue(row, column.getValue, value));
1579
1559
  }
1580
1560
 
1581
1561
  this.setState({
@@ -1586,7 +1566,7 @@ class AIOTableCell extends _react.Component {
1586
1566
 
1587
1567
  getInput(row, column) {
1588
1568
  let {
1589
- getCellValue
1569
+ fn
1590
1570
  } = this.context;
1591
1571
  let {
1592
1572
  attrs,
@@ -1603,7 +1583,7 @@ class AIOTableCell extends _react.Component {
1603
1583
  } = this.state;
1604
1584
 
1605
1585
  if (getValue) {
1606
- value = getCellValue(row, getValue, column.field);
1586
+ value = fn.getCellValue(row, getValue);
1607
1587
  }
1608
1588
 
1609
1589
  if (disabled(row)) {
@@ -1626,7 +1606,7 @@ class AIOTableCell extends _react.Component {
1626
1606
  className: 'aio-table-input-container'
1627
1607
  }, /*#__PURE__*/_react.default.createElement("input", _extends({}, props, {
1628
1608
  style: {
1629
- textAlign: column.justify ? 'center' : undefined
1609
+ textAlign: column.justify || type === 'number' ? 'center' : undefined
1630
1610
  },
1631
1611
  onChange: e => this.setState({
1632
1612
  value: e.target.value
@@ -1763,10 +1743,12 @@ class AIOTableCell extends _react.Component {
1763
1743
  }
1764
1744
 
1765
1745
  getProps(row, column, content) {
1766
- let title = column.getTooltip ? column.getTooltip(row) : typeof content === 'string' ? content : undefined;
1746
+ let attrs = this.context.getCellAttrs(row, column);
1747
+ let title = typeof content === 'string' ? content : undefined;
1767
1748
  return {
1768
1749
  ref: this.dom,
1769
1750
  title,
1751
+ ...attrs,
1770
1752
  style: this.getStyle(column, row),
1771
1753
  className: this.getClassName(row, column)
1772
1754
  };
@@ -1799,6 +1781,11 @@ class AIOTableCell extends _react.Component {
1799
1781
  loading
1800
1782
  } = this.state;
1801
1783
  let content = this.getContent(row, column, value);
1784
+
1785
+ if (column.affix) {
1786
+ content = content + ' ' + column.affix;
1787
+ }
1788
+
1802
1789
  let cell;
1803
1790
 
1804
1791
  if (loading) {
@@ -1847,31 +1834,47 @@ class AIOTableCell extends _react.Component {
1847
1834
  _defineProperty(AIOTableCell, "contextType", AioTableContext);
1848
1835
 
1849
1836
  class AIOTableFilter extends _react.Component {
1850
- change(obj) {
1837
+ constructor(...args) {
1838
+ super(...args);
1839
+
1840
+ _defineProperty(this, "dom", /*#__PURE__*/(0, _react.createRef)());
1841
+ }
1842
+
1843
+ async change(obj) {
1851
1844
  let {
1852
- onChangeFilter,
1853
- filterDictionary,
1854
- SetState
1845
+ SetState,
1846
+ columns
1855
1847
  } = this.context;
1856
1848
  let {
1857
1849
  column
1858
1850
  } = this.props;
1859
- filterDictionary[column._index] = { ...filterDictionary[column._index],
1860
- ...obj
1851
+ column = { ...column,
1852
+ filter: { ...column.filter,
1853
+ ...obj
1854
+ }
1861
1855
  };
1856
+ let approve = true;
1862
1857
 
1863
- if (onChangeFilter) {
1864
- onChangeFilter(filterDictionary);
1858
+ if (column.filter.onChange) {
1859
+ let loading = (0, _jquery.default)(this.dom.current).parents('.aio-table').find('.aio-table-main-loading');
1860
+ loading.css({
1861
+ display: 'flex'
1862
+ });
1863
+ approve = await newFilter.onChange(column.filter);
1864
+ loading.css({
1865
+ display: 'none'
1866
+ });
1865
1867
  }
1866
1868
 
1867
- SetState({
1868
- filterDictionary
1869
- });
1869
+ if (approve !== false) {
1870
+ SetState({
1871
+ columns: columns.map(o => o.realIndex === column.realIndex ? column : o)
1872
+ });
1873
+ }
1870
1874
  }
1871
1875
 
1872
1876
  render() {
1873
1877
  var {
1874
- filterDictionary,
1875
1878
  rtl,
1876
1879
  translate
1877
1880
  } = this.context;
@@ -1883,35 +1886,40 @@ class AIOTableFilter extends _react.Component {
1883
1886
  return null;
1884
1887
  }
1885
1888
 
1886
- if (!filterDictionary[column._index]) {
1887
- return null;
1888
- }
1889
-
1890
- let {
1891
- items,
1892
- booleanType
1893
- } = filterDictionary[column._index];
1894
1889
  let {
1895
- type
1890
+ items = [],
1891
+ booleanType = 'or',
1892
+ type = 'text'
1896
1893
  } = column.filter;
1897
1894
  let icon = items.length ? aioTableGetSvg('filterActive', {
1898
1895
  className: 'has-filter'
1899
1896
  }) : aioTableGetSvg('filter');
1900
1897
  return /*#__PURE__*/_react.default.createElement("div", {
1901
- className: "aio-table-filter-icon"
1898
+ className: "aio-table-filter-icon",
1899
+ ref: this.dom,
1900
+ onClick: () => {
1901
+ (0, _jquery.default)('.aio-table-title').css({
1902
+ zIndex: 100
1903
+ });
1904
+ (0, _jquery.default)(`[data-uniq-id = ${this.props.dataUniqId}]`).css({
1905
+ zIndex: 1000
1906
+ });
1907
+ }
1902
1908
  }, /*#__PURE__*/_react.default.createElement(_aioButton.default, {
1903
1909
  type: "button",
1904
1910
  rtl: rtl,
1905
1911
  caret: false,
1906
1912
  openRelatedTo: ".aio-table",
1907
1913
  text: icon,
1908
- popOver: () => /*#__PURE__*/_react.default.createElement(AIOTableFilterPopup, {
1909
- translate,
1910
- type,
1911
- items,
1912
- booleanType,
1913
- onChange: obj => this.change(obj)
1914
- })
1914
+ popOver: () => {
1915
+ return /*#__PURE__*/_react.default.createElement(AIOTableFilterPopup, {
1916
+ translate,
1917
+ type,
1918
+ items,
1919
+ booleanType,
1920
+ onChange: obj => this.change(obj)
1921
+ });
1922
+ }
1915
1923
  }));
1916
1924
  }
1917
1925
 
@@ -2007,7 +2015,7 @@ class AIOTableFilterItem extends _react.Component {
2007
2015
  getOptions(type, translate) {
2008
2016
  let options = [];
2009
2017
 
2010
- if (type !== 'number') {
2018
+ if (type !== 'number' && type !== 'date') {
2011
2019
  options.push( /*#__PURE__*/_react.default.createElement("option", {
2012
2020
  key: "contain",
2013
2021
  value: "contain"
@@ -2088,7 +2096,8 @@ class AIOTableFilterItem extends _react.Component {
2088
2096
  function ATFN({
2089
2097
  getProps,
2090
2098
  getState,
2091
- setState
2099
+ setState,
2100
+ getContext
2092
2101
  }) {
2093
2102
  let $$ = {
2094
2103
  fixPersianAndArabicNumbers(str) {
@@ -2118,9 +2127,9 @@ function ATFN({
2118
2127
  for (let j = 0; j < columns.length; j++) {
2119
2128
  let {
2120
2129
  title,
2121
- _index
2130
+ realIndex
2122
2131
  } = columns[j];
2123
- let res = row._values[_index];
2132
+ let res = row._values[realIndex];
2124
2133
  obj[title] = res !== undefined ? $$.fixPersianAndArabicNumbers(res) : "";
2125
2134
  }
2126
2135
 
@@ -2182,13 +2191,14 @@ function ATFN({
2182
2191
  document.body.removeChild(link);
2183
2192
  },
2184
2193
 
2185
- getSliderCell({
2186
- colors = ['#eee', 'dodgerblue'],
2187
- start = 0,
2188
- end = 100,
2189
- value,
2190
- editValue = value => value
2191
- }) {
2194
+ getSliderCell(template, val) {
2195
+ let {
2196
+ colors = ['#eee', 'dodgerblue'],
2197
+ start = 0,
2198
+ end = 100,
2199
+ value = val,
2200
+ editValue = value => value
2201
+ } = template;
2192
2202
  let {
2193
2203
  rowHeight,
2194
2204
  rtl
@@ -2248,8 +2258,8 @@ function ATFN({
2248
2258
  },
2249
2259
 
2250
2260
  getOptionsCell({
2251
- options = []
2252
- }) {
2261
+ options
2262
+ }, row) {
2253
2263
  return /*#__PURE__*/_react.default.createElement(_aioButton.default, {
2254
2264
  type: "select",
2255
2265
  caret: false,
@@ -2262,17 +2272,49 @@ function ATFN({
2262
2272
  }) => {
2263
2273
  return {
2264
2274
  text,
2265
- before: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, icon, /*#__PURE__*/_react.default.createElement("div", {
2266
- style: {
2267
- width: 6
2268
- }
2269
- })),
2270
- onClick
2275
+ before: icon,
2276
+ onClick: () => onClick(row)
2271
2277
  };
2272
2278
  })
2273
2279
  });
2274
2280
  },
2275
2281
 
2282
+ getCheckboxCell(template, value, row) {
2283
+ let {
2284
+ color,
2285
+ onChange,
2286
+ size = 24
2287
+ } = template;
2288
+ let style = {
2289
+ width: size,
2290
+ height: size
2291
+ };
2292
+
2293
+ if (!!value) {
2294
+ return /*#__PURE__*/_react.default.createElement("svg", {
2295
+ style: style,
2296
+ viewBox: `0,0,24,24`,
2297
+ className: "aio-table-checkbox checked",
2298
+ onClick: () => onChange(row, false)
2299
+ }, /*#__PURE__*/_react.default.createElement("path", {
2300
+ fill: color,
2301
+ d: "M10,17L5,12L6.41,10.58L10,14.17L17.59,6.58L19,8M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3Z"
2302
+ }));
2303
+ } else {
2304
+ return /*#__PURE__*/_react.default.createElement("svg", {
2305
+ style: style,
2306
+ viewBox: `0,0,24,24`,
2307
+ className: "aio-table-checkbox",
2308
+ onClick: () => onChange(row, true)
2309
+ }, /*#__PURE__*/_react.default.createElement("path", {
2310
+ fill: color,
2311
+ "ng-attr-fill": "{{icon.color}}",
2312
+ "ng-attr-d": "{{icon.data}}",
2313
+ d: "M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3M19,5V19H5V5H19Z"
2314
+ }));
2315
+ }
2316
+ },
2317
+
2276
2318
  getGanttCell(row, template) {
2277
2319
  let {
2278
2320
  rtl
@@ -2285,24 +2327,9 @@ function ATFN({
2285
2327
  getProgress = () => false,
2286
2328
  getText = () => false,
2287
2329
  getStart,
2288
- getEnd
2330
+ getEnd,
2331
+ padding = 36
2289
2332
  } = template;
2290
-
2291
- if (typeof getStart !== 'function') {
2292
- console.error('aio table => gantt column => column getStart property is not a function');
2293
- return '';
2294
- }
2295
-
2296
- if (typeof getEnd !== 'function') {
2297
- console.error('aio table => gantt column => column getEnd property is not a function');
2298
- return '';
2299
- }
2300
-
2301
- if (typeof getKeys !== 'function') {
2302
- console.error('aio table => gantt column => column getKeys property is not a function');
2303
- return '';
2304
- }
2305
-
2306
2333
  let keys = getKeys();
2307
2334
 
2308
2335
  if (!Array.isArray(keys)) {
@@ -2310,15 +2337,20 @@ function ATFN({
2310
2337
  return '';
2311
2338
  }
2312
2339
 
2313
- let color = getColor(row);
2314
- let backgroundColor = getBackgroundColor(row);
2315
- let progress = getProgress(row);
2316
- let text = getText(row);
2317
- let startIndex = keys.indexOf(getStart(row));
2318
- let endIndex = keys.indexOf(getEnd(row));
2319
- let background = progress === false ? color : `linear-gradient(to ${rtl ? 'left' : 'right'},rgba(0,0,0,.1) 0%,rgba(0,0,0,.1) ${progress}% ,transparent ${progress}%,transparent 100%)`;
2340
+ let color = $$.getCellValue(row, getColor);
2341
+ let backgroundColor = $$.getCellValue(row, getBackgroundColor);
2342
+ let progress = $$.getCellValue(row, getProgress);
2343
+ let text = $$.getCellValue(row, getText);
2344
+ let startIndex = keys.indexOf($$.getCellValue(row, getStart));
2345
+ let endIndex = keys.indexOf($$.getCellValue(row, getEnd));
2346
+ let background = progress === false ? color : `linear-gradient(to ${rtl ? 'left' : 'right'},rgba(0,0,0,.2) 0%,rgba(0,0,0,.2) ${progress}% ,transparent ${progress}%,transparent 100%)`;
2320
2347
  let flags = getFlags();
2321
2348
  return /*#__PURE__*/_react.default.createElement(_rRangeSlider.default, {
2349
+ attrs: {
2350
+ style: {
2351
+ padding: `0 ${+padding}px`
2352
+ }
2353
+ },
2322
2354
  start: 0,
2323
2355
  editValue: value => keys[value],
2324
2356
  end: keys.length - 1,
@@ -2369,25 +2401,41 @@ function ATFN({
2369
2401
  },
2370
2402
 
2371
2403
  handleOutsideClick() {
2372
- (0, _jquery.default)(window).bind('click', e => {
2373
- var {
2374
- focused
2375
- } = getState();
2404
+ (0, _jquery.default)(window).unbind('click', $$.outSideClick);
2405
+ (0, _jquery.default)(window).bind('click', $$.outSideClick);
2406
+ },
2376
2407
 
2377
- if (focused === false) {
2378
- return;
2379
- }
2408
+ outSideClick(e) {
2409
+ let {
2410
+ focused
2411
+ } = getState();
2380
2412
 
2381
- var target = (0, _jquery.default)(e.target);
2413
+ if (focused === false) {
2414
+ return;
2415
+ }
2382
2416
 
2383
- if (target.parents('.aio-table-cell').length !== 0 || target.hasClass('aio-table-cell')) {
2384
- return;
2385
- }
2417
+ let target = (0, _jquery.default)(e.target);
2386
2418
 
2387
- setState({
2388
- focused: false
2389
- });
2390
- });
2419
+ if (target.hasClass('aio-table-cell')) {
2420
+ return;
2421
+ }
2422
+
2423
+ if (target.parents('.aio-table-input-container').length) {
2424
+ return;
2425
+ }
2426
+
2427
+ if (target.parents('.aio-table-cell-content').length) {
2428
+ return;
2429
+ }
2430
+
2431
+ if (target.parents('.aio-table-cell').length) {
2432
+ return;
2433
+ }
2434
+
2435
+ (0, _jquery.default)(window).unbind('click', $$.outSideClick);
2436
+ setState({
2437
+ focused: false
2438
+ }, 'outsideClick');
2391
2439
  },
2392
2440
 
2393
2441
  getCardRowCount() {
@@ -2485,25 +2533,6 @@ function ATFN({
2485
2533
  $$['scroll' + index] = false;
2486
2534
  },
2487
2535
 
2488
- getGroupDictionaty() {
2489
- let {
2490
- id
2491
- } = getProps();
2492
-
2493
- if (id === undefined) {
2494
- return {};
2495
- }
2496
-
2497
- let groupDictionary = localStorage.getItem('aio table group' + id);
2498
-
2499
- if (groupDictionary === null || groupDictionary === undefined) {
2500
- localStorage.setItem('aio table group' + id, '{}');
2501
- return {};
2502
- } else {
2503
- return JSON.parse(groupDictionary);
2504
- }
2505
- },
2506
-
2507
2536
  getOpenDictionary() {
2508
2537
  let {
2509
2538
  id
@@ -2538,319 +2567,423 @@ function ATFN({
2538
2567
  return parseInt(list.map(o => o.length === 1 ? '0' + o : o).join(''));
2539
2568
  },
2540
2569
 
2541
- getSorts(toolbar) {
2570
+ setCellValue: (row, getValue, value) => {
2571
+ //row is used in eval
2542
2572
  let {
2543
- onChangeSort
2573
+ model
2544
2574
  } = getProps();
2545
- let {
2546
- sorts,
2547
- columns = [],
2548
- getCellValue
2549
- } = getState();
2550
- let sortTitles = sorts.map(o => o.title);
2575
+ let evalText;
2551
2576
 
2552
- for (let i = 0; i < columns.length; i++) {
2553
- if (!columns[i].sort) {
2554
- continue;
2577
+ if (typeof value === 'string') {
2578
+ evalText = `row.${getValue} = "${value}"`;
2579
+ } else {
2580
+ evalText = 'row.' + getValue + ' = ' + JSON.stringify(value);
2581
+ }
2582
+
2583
+ eval(evalText);
2584
+ return model;
2585
+ },
2586
+ getCellValue: (row, getValue) => {
2587
+ try {
2588
+ if (typeof getValue === 'function') {
2589
+ return getValue(row);
2555
2590
  }
2556
2591
 
2557
- if (sortTitles.indexOf(columns[i].title) !== -1) {
2558
- continue;
2592
+ if (typeof getValue === 'string') {
2593
+ let result;
2594
+ eval('result = row.' + getValue);
2595
+ return result;
2559
2596
  }
2560
2597
 
2561
- columns[i]._addedToSorts = true;
2562
- let column = columns[i];
2598
+ return;
2599
+ } catch {
2600
+ return;
2601
+ }
2602
+ },
2563
2603
 
2564
- if (column.sort === true) {
2565
- column.sort = {};
2566
- }
2604
+ async onChangeSort(obj, colIndex) {
2605
+ let {
2606
+ columns
2607
+ } = getState();
2608
+ columns = [...columns];
2609
+ let column = { ...columns[colIndex]
2610
+ };
2611
+ column.sort = { ...column.sort,
2612
+ ...obj
2613
+ };
2614
+ let newColumns = columns.map((o, i) => i === colIndex ? column : o);
2615
+ let approve = true;
2567
2616
 
2617
+ if (column.sort.onChange) {
2568
2618
  let {
2569
- sort
2570
- } = columns[i];
2571
- let a = sort.title || column.title || '';
2572
- let title = typeof a === 'function' ? a() : a;
2573
- let getValue = sort.getValue || column.getValue;
2574
- let field = sort.field || column.field;
2575
- let {
2576
- toggle = true,
2577
- dir = 'inc',
2578
2619
  active = true,
2579
- type
2580
- } = sort;
2581
- sorts.push({
2582
- title,
2583
- dir,
2620
+ dir = 'inc'
2621
+ } = column.sort;
2622
+ approve = await column.sort.onChange({
2584
2623
  active,
2585
- toggle,
2586
- getValue,
2587
- type,
2588
- field
2624
+ dir
2589
2625
  });
2590
2626
  }
2591
2627
 
2592
- let Sorts = sorts.map(o => {
2593
- return { ...o,
2594
- onChangeDir: () => {
2595
- o.dir = o.dir === 'dec' ? 'inc' : 'dec';
2596
- setState({
2597
- sorts
2598
- });
2628
+ if (approve !== false) {
2629
+ setState({
2630
+ columns: newColumns
2631
+ });
2632
+ }
2633
+ },
2599
2634
 
2600
- if (onChangeSort) {
2601
- onChangeSort(Sorts.filter(o => o.active !== false));
2602
- }
2603
- },
2604
- onChangeActive: () => {
2605
- o.active = o.active === undefined ? true : o.active;
2606
- o.active = !o.active;
2607
- setState({
2608
- sorts
2609
- });
2635
+ getSorts({
2636
+ column,
2637
+ sorts,
2638
+ sortOptions,
2639
+ columnTitle,
2640
+ colIndex
2641
+ }) {
2642
+ let {
2643
+ sort
2644
+ } = column;
2645
+ let {
2646
+ title = columnTitle || '',
2647
+ getValue = column.getValue,
2648
+ type,
2649
+ active = true,
2650
+ toggle = true,
2651
+ dir = 'inc',
2652
+ onChange
2653
+ } = sort;
2610
2654
 
2611
- if (onChangeSort) {
2612
- onChangeSort(Sorts.filter(o => o.active !== false));
2613
- }
2655
+ if (type === 'date') {
2656
+ getValue = row => {
2657
+ let {
2658
+ sort
2659
+ } = column;
2660
+ let {
2661
+ getValue = column.getValue
2662
+ } = sort;
2663
+ let value = $$.getCellValue(row, getValue);
2664
+
2665
+ if (typeof value !== 'string') {
2666
+ return 0;
2614
2667
  }
2668
+
2669
+ return $$.getDateNumber(value);
2615
2670
  };
2616
- });
2617
- let result = [];
2671
+ }
2618
2672
 
2619
- for (let i = 0; i < Sorts.length; i++) {
2620
- let sort = Sorts[i];
2621
- let {
2622
- getValue,
2623
- dir = 'inc',
2624
- title,
2625
- active = true,
2626
- toggle = true,
2627
- type,
2628
- onChangeDir,
2629
- onChangeActive,
2630
- field
2631
- } = sort;
2673
+ sorts.push({
2674
+ title,
2675
+ dir,
2676
+ active,
2677
+ toggle,
2678
+ getValue,
2679
+ type,
2680
+ onChange
2681
+ });
2632
2682
 
2633
- if (!title) {
2634
- console.error('aio table => missing sort title property');
2635
- continue;
2636
- }
2683
+ if (toggle) {
2684
+ sortOptions.push({
2685
+ text: title,
2686
+ checked: !!active,
2687
+ onClick: () => $$.onChangeSort({
2688
+ active: !active
2689
+ }, colIndex),
2690
+ after: /*#__PURE__*/_react.default.createElement("div", {
2691
+ style: {
2692
+ width: '30px',
2693
+ display: 'flex',
2694
+ justifyContent: 'flex-end'
2695
+ }
2696
+ }, aioTableGetSvg(dir === 'dec' ? 'arrowDown' : 'arrowUp', {
2697
+ onClick: e => {
2698
+ e.stopPropagation();
2699
+ $$.onChangeSort({
2700
+ dir: dir === 'dec' ? 'inc' : 'dec'
2701
+ }, colIndex);
2702
+ }
2703
+ }))
2704
+ });
2705
+ }
2706
+ },
2637
2707
 
2638
- if (active === true) {
2639
- if (type === 'date') {
2640
- let newGetValue = row => {
2641
- let value = getCellValue(row, getValue, field);
2708
+ getToggles(obj) {
2709
+ let {
2710
+ column,
2711
+ toggleOptions,
2712
+ colIndex,
2713
+ columnTitle
2714
+ } = obj;
2715
+ let {
2716
+ columns
2717
+ } = getState();
2718
+ toggleOptions.push({
2719
+ text: columnTitle,
2720
+ checked: column.show !== false,
2721
+ onClick: () => {
2722
+ //change columns imutable(prevent change columns directly)
2723
+ let column = { ...obj.column,
2724
+ show: !obj.column.show
2725
+ };
2642
2726
 
2643
- if (typeof value !== 'string') {
2644
- return 0;
2727
+ if (column.storageKey) {
2728
+ column = { ...column,
2729
+ _storageObj: { ...column._storageObj,
2730
+ show: column.show
2645
2731
  }
2646
-
2647
- return $$.getDateNumber(value);
2648
2732
  };
2649
-
2650
- result.push({
2651
- getValue: row => newGetValue(row),
2652
- dir
2653
- });
2654
- } else {
2655
- result.push({
2656
- getValue,
2657
- dir
2658
- });
2733
+ localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
2659
2734
  }
2660
- }
2661
2735
 
2662
- if (toggle) {
2663
- toolbar.show = true;
2664
- toolbar.sort.push({
2665
- text: title,
2666
- checked: active === true,
2667
- after: /*#__PURE__*/_react.default.createElement("div", {
2668
- style: {
2669
- width: '30px',
2670
- display: 'flex',
2671
- justifyContent: 'flex-end'
2672
- }
2673
- }, aioTableGetSvg(dir === 'dec' ? 'arrowDown' : 'arrowUp', {
2674
- onClick: e => {
2675
- e.stopPropagation();
2676
- onChangeDir();
2677
- }
2678
- })),
2679
- onClick: () => onChangeActive()
2736
+ setState({
2737
+ columns: columns.map((o, i) => i === column.realIndex ? column : o)
2680
2738
  });
2681
2739
  }
2682
- }
2683
-
2684
- return result;
2740
+ });
2685
2741
  },
2686
2742
 
2687
- getGroups(toolbar) {
2688
- var {
2689
- id
2690
- } = getProps();
2691
- var {
2692
- groups,
2693
- groupDictionary
2694
- } = getState();
2695
- let result = [];
2696
-
2697
- for (let i = 0; i < groups.length; i++) {
2698
- let group = groups[i];
2699
- let {
2700
- title,
2701
- active = true,
2702
- toggle = true
2703
- } = group;
2704
-
2705
- if (!title) {
2706
- console.error('aio table => missing group title property');
2707
- continue;
2708
- }
2709
-
2710
- groupDictionary[title] = groupDictionary[title] === undefined ? active : groupDictionary[title];
2711
-
2712
- if (groupDictionary[title]) {
2713
- result.push(group);
2714
- }
2715
-
2716
- if (toggle) {
2717
- toolbar.show = true;
2718
- toolbar.groupBy.push({
2719
- text: title,
2720
- checked: groupDictionary[title],
2721
- onClick: () => {
2722
- groupDictionary[title] = !groupDictionary[title];
2743
+ getFreezes({
2744
+ column,
2745
+ colIndex,
2746
+ columnTitle,
2747
+ freezeOptions,
2748
+ freezeColumns,
2749
+ unFreezeColumns
2750
+ }) {
2751
+ (column.freeze ? freezeColumns : unFreezeColumns).push(column);
2723
2752
 
2724
- if (id) {
2725
- localStorage.setItem('aio table group' + id, JSON.stringify(groupDictionary));
2726
- }
2753
+ if (!column.toggleFreeze) {
2754
+ return;
2755
+ }
2727
2756
 
2728
- setState({
2729
- groupDictionary
2730
- });
2731
- }
2757
+ freezeOptions.push({
2758
+ text: columnTitle,
2759
+ checked: column.freeze === true,
2760
+ onClick: () => {
2761
+ let {
2762
+ columns
2763
+ } = getState();
2764
+ columns = [...columns];
2765
+ let column = { ...columns[colIndex]
2766
+ };
2767
+ column.freeze = !column.freeze;
2768
+ setState({
2769
+ columns: columns.map((o, i) => i === colIndex ? column : o)
2732
2770
  });
2733
2771
  }
2734
- }
2735
-
2736
- return result;
2772
+ });
2737
2773
  },
2738
2774
 
2739
- setColumnByStorage(column) {
2740
- if (column.storageKey && !column._readStorage) {
2775
+ updateColumnByStorage(column) {
2776
+ let {
2777
+ storageKey,
2778
+ _readStorage
2779
+ } = column;
2780
+
2781
+ if (storageKey && !_readStorage) {
2741
2782
  column._readStorage = true;
2742
2783
  let storageStr = localStorage.getItem('aio-table-column-storage-' + column.storageKey);
2784
+ let storageObj;
2743
2785
 
2744
2786
  if (!storageStr || storageStr === null) {
2745
- column._storageObj = {};
2746
- localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
2787
+ storageObj = {};
2788
+ localStorage.setItem('aio-table-column-storage-' + column.storageKey, '{}');
2747
2789
  } else {
2748
- column._storageObj = JSON.parse(storageStr);
2790
+ storageObj = JSON.parse(storageStr);
2749
2791
  }
2750
2792
 
2751
- if (column._storageObj.show !== undefined) {
2752
- column.show = column._storageObj.show;
2753
- } else {
2754
- column.show = column.show === undefined ? true : column.show;
2793
+ if (storageObj.show !== undefined) {
2794
+ column.show = storageObj.show;
2755
2795
  }
2756
2796
 
2757
- if (column._storageObj.width !== undefined) {
2758
- column.width = column._storageObj.width;
2759
- } else {
2760
- column.width = column.width || 'auto';
2797
+ if (storageObj.width !== undefined) {
2798
+ column.width = storageObj.width;
2761
2799
  }
2762
- } else {
2763
- column.show = column.show === undefined ? true : column.show;
2764
- column.width = column.width || 'auto';
2800
+
2801
+ column._storageObj = storageObj;
2765
2802
  }
2766
2803
  },
2767
2804
 
2768
- getFreezes(index, columnDetails, toolbar) {
2805
+ getDetails() {
2769
2806
  let {
2770
- columns
2807
+ columns,
2808
+ groups
2771
2809
  } = getState();
2772
- let column = columns[index];
2810
+ columns = [...columns];
2811
+ let sorts = [];
2812
+ let freezeColumns = [],
2813
+ unFreezeColumns = [],
2814
+ freezeOptions = [],
2815
+ sortOptions = [],
2816
+ toggleOptions = [],
2817
+ groupOptions = [];
2818
+ let excelColumns = [],
2819
+ visibleColumns = [],
2820
+ search = false;
2821
+ let groupTitles = groups.map(o => o.title);
2822
+ let renderIndex = 0;
2773
2823
 
2774
- if (column.freeze) {
2775
- columnDetails.freeze.active = true;
2776
- columnDetails.freeze.freezeColumns.push(column);
2777
- } else {
2778
- columnDetails.freeze.unFreezeColumns.push(column);
2779
- }
2780
-
2781
- if (column.toggleFreeze) {
2782
- toolbar.show = true;
2783
- toolbar.freeze.push({
2784
- text: column.title,
2785
- checked: column.freeze === true,
2786
- onClick: () => {
2787
- let state = columns[index].freeze === true ? true : false;
2788
- let column = { ...columns[index],
2789
- freeze: !state
2790
- };
2791
- setState({
2792
- columns: columns.map((c, i) => {
2793
- if (i === index) {
2794
- return column;
2795
- }
2796
-
2797
- return c;
2798
- })
2824
+ for (let i = 0; i < columns.length; i++) {
2825
+ columns[i].realIndex = i;
2826
+
2827
+ if (columns[i].sort === true) {
2828
+ columns[i].sort = {};
2829
+ }
2830
+
2831
+ if (columns[i].filter === true) {
2832
+ columns[i].filter = {
2833
+ items: [],
2834
+ booleanType: 'or',
2835
+ type: 'text'
2836
+ };
2837
+ }
2838
+
2839
+ if (columns[i].group === true) {
2840
+ columns[i].group = {};
2841
+ }
2842
+
2843
+ columns[i].width = columns[i].width || 'auto';
2844
+ let column = { ...columns[i]
2845
+ };
2846
+ column.realIndex = i;
2847
+ $$.updateColumnByStorage(column);
2848
+ let {
2849
+ title: columnTitle,
2850
+ show = true,
2851
+ sort,
2852
+ toggleShow,
2853
+ excel
2854
+ } = column;
2855
+ columnTitle = typeof columnTitle === 'function' ? columnTitle() : columnTitle;
2856
+ column.show = typeof show === 'function' ? show() : show;
2857
+
2858
+ if (column.search) {
2859
+ search = true;
2860
+ }
2861
+
2862
+ if (column.group && groupTitles.indexOf(columnTitle) === -1) {
2863
+ let {
2864
+ title = columnTitle,
2865
+ active = true,
2866
+ toggle = true,
2867
+ storageKey = column.storageKey,
2868
+ getValue = column.getValue
2869
+ } = column.group;
2870
+ groups.push({
2871
+ title,
2872
+ active,
2873
+ toggle,
2874
+ storageKey,
2875
+ getValue
2876
+ });
2877
+ }
2878
+
2879
+ if (column.show) {
2880
+ column.renderIndex = renderIndex;
2881
+ columns[i].renderIndex = renderIndex;
2882
+ renderIndex++;
2883
+ visibleColumns.push(column);
2884
+
2885
+ if (excel) {
2886
+ excelColumns.push(column);
2887
+ }
2888
+
2889
+ if (sort) {
2890
+ $$.getSorts({
2891
+ column,
2892
+ columnTitle,
2893
+ sorts,
2894
+ sortOptions,
2895
+ colIndex: i
2799
2896
  });
2800
2897
  }
2801
- });
2898
+
2899
+ $$.getFreezes({
2900
+ column,
2901
+ colIndex: i,
2902
+ columnTitle,
2903
+ freezeOptions,
2904
+ freezeColumns,
2905
+ unFreezeColumns
2906
+ });
2907
+ }
2908
+
2909
+ if (toggleShow) {
2910
+ $$.getToggles({
2911
+ column,
2912
+ columnTitle,
2913
+ toggleOptions,
2914
+ colIndex: i
2915
+ });
2916
+ }
2802
2917
  }
2918
+
2919
+ $$.getGroups(groupOptions);
2920
+ return {
2921
+ sorts,
2922
+ sortOptions,
2923
+ freezeColumns,
2924
+ unFreezeColumns,
2925
+ freezeOptions,
2926
+ toggleOptions,
2927
+ groupOptions,
2928
+ excelColumns,
2929
+ columns: visibleColumns,
2930
+ search
2931
+ };
2803
2932
  },
2804
2933
 
2805
- getToggleShows(index, toolbar) {
2806
- let {
2807
- columns
2934
+ getGroups(groupOptions) {
2935
+ var {
2936
+ groups
2808
2937
  } = getState();
2809
- let column = columns[index];
2810
- let {
2811
- show,
2812
- storageKey
2813
- } = column;
2814
- let title = typeof column.title === 'function' ? column.title() : column.title;
2815
- toolbar.show = true;
2816
- toolbar.toggle.push({
2817
- text: title,
2818
- checked: show !== false,
2819
- onClick: () => {
2820
- //change columns imutable(prevent change columns directly)
2821
- let {
2822
- columns
2823
- } = getState();
2824
- let column = columns[index];
2825
- let newColumn;
2826
2938
 
2827
- if (storageKey) {
2828
- let newShow = !column._storageObj.show;
2829
- let newStorageObj = { ...column._storageObj,
2830
- show: newShow
2831
- };
2832
- newColumn = { ...column,
2833
- _storageObj: newStorageObj,
2834
- show: newShow
2835
- };
2836
- localStorage.setItem('aio-table-column-storage-' + newColumn.storageKey, JSON.stringify(newColumn._storageObj));
2939
+ for (let i = 0; i < groups.length; i++) {
2940
+ let group = groups[i];
2941
+ let {
2942
+ title,
2943
+ active = true,
2944
+ toggle = true,
2945
+ storageKey,
2946
+ _readStorage
2947
+ } = group;
2948
+
2949
+ if (storageKey && !_readStorage) {
2950
+ group._readStorage = true;
2951
+ let storageActive = localStorage.getItem('aio table group' + storageKey);
2952
+
2953
+ if (storageActive === null) {
2954
+ storageActive = true;
2955
+ localStorage.setItem('aio table group' + storageKey, JSON.stringify(storageAtive));
2837
2956
  } else {
2838
- newColumn = { ...column,
2839
- show: !column.show
2840
- };
2957
+ storageActive = JSON.parse(storageActive);
2841
2958
  }
2842
2959
 
2843
- setState({
2844
- columns: columns.map((c, i) => {
2845
- if (i === index) {
2846
- return newColumn;
2960
+ active = storageActive;
2961
+ }
2962
+
2963
+ group.active = active;
2964
+
2965
+ if (toggle) {
2966
+ groupOptions.push({
2967
+ text: title,
2968
+ checked: active === true,
2969
+ onClick: () => {
2970
+ let {
2971
+ groups
2972
+ } = getState();
2973
+ let group = groups[i];
2974
+ group.active = !group.active;
2975
+
2976
+ if (storageKey) {
2977
+ localStorage.setItem('aio table group' + storageKey, JSON.stringify(group.active));
2847
2978
  }
2848
2979
 
2849
- return c;
2850
- })
2980
+ setState({
2981
+ groups
2982
+ });
2983
+ }
2851
2984
  });
2852
2985
  }
2853
- });
2986
+ }
2854
2987
  },
2855
2988
 
2856
2989
  isContain(text, subtext) {
@@ -3015,13 +3148,12 @@ function ATFN({
3015
3148
 
3016
3149
  getFilterResult(column, value) {
3017
3150
  let {
3018
- filterDictionary
3019
- } = getState();
3020
- let filters = filterDictionary[column._index].items;
3151
+ items = [],
3152
+ booleanType = 'or'
3153
+ } = column.filter;
3021
3154
 
3022
- if (filters.length) {
3023
- let booleanType = filterDictionary[column._index].booleanType;
3024
- return $$['getFilterResult_' + booleanType](filters, value);
3155
+ if (items.length) {
3156
+ return $$['getFilterResult_' + booleanType](items, value);
3025
3157
  }
3026
3158
 
3027
3159
  return true;
@@ -3090,31 +3222,6 @@ function ATFN({
3090
3222
  }));
3091
3223
  },
3092
3224
 
3093
- getBodyStyle(Toolbar) {
3094
- let {
3095
- paging
3096
- } = getState();
3097
- let {
3098
- padding
3099
- } = getProps();
3100
- var def = padding,
3101
- top = 0;
3102
-
3103
- if (paging) {
3104
- def += 36;
3105
- }
3106
-
3107
- if (Toolbar !== null) {
3108
- def += 36;
3109
- top += 36;
3110
- }
3111
-
3112
- return {
3113
- height: `calc(100% - ${def}px)`,
3114
- top
3115
- };
3116
- },
3117
-
3118
3225
  toggleRow(row) {
3119
3226
  var {
3120
3227
  openDictionary
@@ -3138,21 +3245,15 @@ function ATFN({
3138
3245
  });
3139
3246
  },
3140
3247
 
3141
- getRow(row, columnDetails) {
3248
+ getRow(row) {
3142
3249
  let {
3143
- visibleColumns: columns,
3144
- freeze
3145
- } = columnDetails;
3146
- var {
3147
- onChangeFilter,
3148
- search
3149
- } = getProps();
3150
- let {
3151
- filterDictionary,
3152
- searchText,
3153
- getCellValue
3250
+ searchText
3154
3251
  } = getState();
3252
+ let {
3253
+ columns
3254
+ } = getContext().details;
3155
3255
  row._values = {};
3256
+ let searchShow;
3156
3257
  let show = true,
3157
3258
  lastColumn,
3158
3259
  isThereAutoColumn = false,
@@ -3161,43 +3262,33 @@ function ATFN({
3161
3262
  unFreezeCells = [];
3162
3263
 
3163
3264
  for (let i = 0; i < columns.length; i++) {
3164
- let column = columns[i],
3165
- value = getCellValue(row, column.getValue, column.field);
3166
- row._values[column._index] = value;
3167
- filterDictionary[column._index] = filterDictionary[column._index] || {
3168
- items: [],
3169
- booleanType: 'or'
3170
- };
3265
+ let column = columns[i];
3266
+ let value = $$.getCellValue(row, column.getValue);
3267
+ row._values[column.realIndex] = value;
3171
3268
 
3172
- if (show && search) {
3173
- if (searchText === '') {
3174
- show = true;
3175
- } else {
3176
- try {
3177
- show = search(row, searchText);
3178
- } catch {
3179
- show = false;
3180
- }
3269
+ if (show && column.search && searchText) {
3270
+ if (searchShow === undefined) {
3271
+ searchShow = false;
3181
3272
  }
3273
+
3274
+ searchShow = searchShow || JSON.stringify(value).toLowerCase().indexOf(searchText.toLowerCase()) !== -1;
3182
3275
  }
3183
3276
 
3184
- if (show && !onChangeFilter) {
3277
+ if (show && column.filter && !column.filter.onChange) {
3185
3278
  show = show && $$.getFilterResult(column, value);
3186
3279
  }
3187
3280
 
3188
3281
  let obj = {
3189
- key: row._index + ',' + column._index,
3282
+ key: row._index + ',' + column.realIndex,
3190
3283
  column,
3191
3284
  value,
3192
3285
  freeze: column.freeze
3193
3286
  };
3194
3287
 
3195
- if (freeze.active) {
3288
+ if ($$.freezeMode) {
3196
3289
  if (column.freeze) {
3197
- column._renderIndex = freezeCells.length;
3198
3290
  freezeCells.push(obj);
3199
3291
  } else {
3200
- column._renderIndex = unFreezeCells.length;
3201
3292
  lastColumn = column;
3202
3293
  unFreezeCells.push(obj);
3203
3294
 
@@ -3206,7 +3297,6 @@ function ATFN({
3206
3297
  }
3207
3298
  }
3208
3299
  } else {
3209
- column._renderIndex = i;
3210
3300
  cells.push(obj);
3211
3301
  lastColumn = column;
3212
3302
 
@@ -3216,7 +3306,7 @@ function ATFN({
3216
3306
  }
3217
3307
  }
3218
3308
 
3219
- row._show = show;
3309
+ row._show = show && searchShow !== false;
3220
3310
 
3221
3311
  if (show) {
3222
3312
  let parents = row._getParents();
@@ -3288,29 +3378,6 @@ function ATFN({
3288
3378
  };
3289
3379
  },
3290
3380
 
3291
- showColumnRelativeGroups(column) {
3292
- var {
3293
- groups
3294
- } = getState();
3295
-
3296
- if (!groups) {
3297
- return true;
3298
- }
3299
-
3300
- if (!groups.length) {
3301
- return true;
3302
- }
3303
-
3304
- if (!column.groupName) {
3305
- return true;
3306
- }
3307
-
3308
- var {
3309
- groupDictionary
3310
- } = getState();
3311
- return groupDictionary[column.groupName] !== true;
3312
- },
3313
-
3314
3381
  getClient(e) {
3315
3382
  return getState().touch ? [e.changedTouches[0].clientX, e.changedTouches[0].clientY] : [e.clientX, e.clientY];
3316
3383
  },
@@ -3369,11 +3436,11 @@ function ATFN({
3369
3436
  let childs = [];
3370
3437
 
3371
3438
  if (getRowChilds) {
3372
- childs = getRowChilds(row) || [];
3439
+ childs = $$.getCellValue(row, getRowChilds) || [];
3373
3440
  row._childsLength = childs.length;
3374
3441
  }
3375
3442
 
3376
- let Row = $$.getRow(row, $$.columnDetails);
3443
+ let Row = $$.getRow(row);
3377
3444
 
3378
3445
  if (row._level === 0) {
3379
3446
  rows.push([]);
@@ -3425,27 +3492,24 @@ function ATFN({
3425
3492
  },
3426
3493
 
3427
3494
  getRowsBySort(rows, sorts) {
3428
- let {
3429
- getCellValue
3430
- } = getState();
3431
-
3432
3495
  if (!sorts.length) {
3433
3496
  return rows;
3434
3497
  }
3435
3498
 
3436
- if (getProps().onChangeSort) {
3437
- return rows;
3438
- }
3439
-
3440
3499
  return rows.sort((a, b) => {
3441
3500
  for (let i = 0; i < sorts.length; i++) {
3442
3501
  let {
3443
3502
  getValue,
3444
3503
  dir,
3445
- field
3504
+ onChange
3446
3505
  } = sorts[i];
3447
- let aValue = getCellValue(a, getValue, field),
3448
- bValue = getCellValue(b, getValue, field);
3506
+
3507
+ if (onChange) {
3508
+ continue;
3509
+ }
3510
+
3511
+ let aValue = $$.getCellValue(a, getValue),
3512
+ bValue = $$.getCellValue(b, getValue);
3449
3513
 
3450
3514
  if (aValue < bValue) {
3451
3515
  return -1 * (dir === 'dec' ? -1 : 1);
@@ -3455,21 +3519,19 @@ function ATFN({
3455
3519
  return 1 * (dir === 'dec' ? -1 : 1);
3456
3520
  }
3457
3521
 
3458
- if (i !== sorts.length - 1) {
3459
- continue;
3522
+ if (i === sorts.length - 1) {
3523
+ return 0;
3460
3524
  }
3461
-
3462
- return 0;
3463
3525
  }
3464
3526
 
3465
3527
  return 0;
3466
3528
  });
3467
3529
  },
3468
3530
 
3469
- getRows(model, columnDetails) {
3531
+ getRows(model, freezeMode) {
3470
3532
  let rows = [];
3471
3533
  $$.realIndex = 0;
3472
- $$.columnDetails = columnDetails;
3534
+ $$.freezeMode = freezeMode;
3473
3535
  $$.getRowsReq(model, rows, 0, [], []);
3474
3536
  let result = [];
3475
3537
 
@@ -3532,8 +3594,7 @@ function ATFN({
3532
3594
  }
3533
3595
 
3534
3596
  var {
3535
- groupsOpen,
3536
- getCellValue
3597
+ groupsOpen
3537
3598
  } = getState();
3538
3599
 
3539
3600
  function msf(obj, _level, parents) {
@@ -3565,7 +3626,7 @@ function ATFN({
3565
3626
  for (let i = 0; i < roots.length; i++) {
3566
3627
  let root = roots[i];
3567
3628
  var obj = newModel;
3568
- let values = groups.map(group => getCellValue(root[0].row, group.getValue, group.field));
3629
+ let values = groups.map(group => $$.getCellValue(root[0].row, group.getValue, group.field));
3569
3630
 
3570
3631
  for (let j = 0; j < values.length; j++) {
3571
3632
  let value = values[j];
@@ -3626,30 +3687,26 @@ function ATFN({
3626
3687
  };
3627
3688
  return {
3628
3689
  exportToExcel: $$.exportToExcel,
3690
+ getDetails: $$.getDetails,
3629
3691
  getSliderCell: $$.getSliderCell,
3630
3692
  getOptionsCell: $$.getOptionsCell,
3631
3693
  getGanttCell: $$.getGanttCell,
3694
+ getCheckboxCell: $$.getCheckboxCell,
3632
3695
  handleOutsideClick: $$.handleOutsideClick,
3633
3696
  onScroll: $$.onScroll,
3634
3697
  getCardRowCount: $$.getCardRowCount,
3635
3698
  getOpenDictionary: $$.getOpenDictionary,
3636
- getGroupDictionaty: $$.getGroupDictionaty,
3637
- getSorts: $$.getSorts,
3638
3699
  getRowsBySort: $$.getRowsBySort,
3639
3700
  getGroups: $$.getGroups,
3640
3701
  getRootsByGroup: $$.getRootsByGroup,
3641
3702
  setColumnByStorage: $$.setColumnByStorage,
3642
- getFreezes: $$.getFreezes,
3643
- getToggleShows: $$.getToggleShows,
3644
3703
  getFilterResult: $$.getFilterResult,
3645
3704
  getLoading: $$.getLoading,
3646
3705
  cubes2: $$.cubes2,
3647
- getBodyStyle: $$.getBodyStyle,
3648
3706
  getRow: $$.getRow,
3649
3707
  getRowById: $$.getRowById,
3650
3708
  getClient: $$.getClient,
3651
3709
  getStateByToggleAll: $$.getStateByToggleAll,
3652
- showColumnRelativeGroups: $$.showColumnRelativeGroups,
3653
3710
  getRootsByPaging: $$.getRootsByPaging,
3654
3711
  getRowsReq: $$.getRowsReq,
3655
3712
  getRowsNested: $$.getRowsNested,
@@ -3658,7 +3715,10 @@ function ATFN({
3658
3715
  getRowsByRoots: $$.getRowsByRoots,
3659
3716
  toggleRow: $$.toggleRow,
3660
3717
  getFullCellStyle: $$.getFullCellStyle,
3661
- getNoData: $$.getNoData
3718
+ getNoData: $$.getNoData,
3719
+ getSortsFromColumns: $$.getSortsFromColumns,
3720
+ getCellValue: $$.getCellValue,
3721
+ setCellValue: $$.setCellValue
3662
3722
  };
3663
3723
  }
3664
3724