aio-table 6.3.2 → 7.0.0

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 +20 -5
  2. package/index.js +880 -910
  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,29 @@ 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 freezeMode = freezeColumns.length !== 0 && unFreezeColumns.length !== 0;
125
+ let rows = this.getRows(sorts, freezeMode);
183
126
  this.rows = rows;
184
- let freezeMode = this.columnDetails.freeze.active;
185
127
  return /*#__PURE__*/_react.default.createElement("div", {
186
- className: 'aio-table-body',
187
- style: this.fn.getBodyStyle(Toolbar)
188
- }, !freezeMode && /*#__PURE__*/_react.default.createElement(AIOTableUnit, {
128
+ className: 'aio-table-body'
129
+ }, !freezeMode && columns.length !== 0 && /*#__PURE__*/_react.default.createElement(AIOTableUnit, {
189
130
  rows: rows,
190
- columns: this.columnDetails.visibleColumns,
131
+ columns: columns,
191
132
  type: "cells"
192
133
  }), freezeMode && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(AIOTableUnit, {
193
134
  key: 0,
194
135
  id: "aio-table-first-split",
195
136
  rows: rows,
196
- columns: this.columnDetails.freeze.freezeColumns,
137
+ columns: freezeColumns,
197
138
  tableIndex: 0,
198
139
  type: "freezeCells",
199
140
  style: {
@@ -207,13 +148,13 @@ class AIOTable extends _react.Component {
207
148
  key: 1,
208
149
  id: "aio-table-second-split",
209
150
  rows: rows,
210
- columns: this.columnDetails.freeze.unFreezeColumns,
151
+ columns: unFreezeColumns,
211
152
  tableIndex: 1,
212
153
  type: "unFreezeCells"
213
154
  })));
214
155
  }
215
156
 
216
- getRows() {
157
+ getRows(sorts, freezeMode) {
217
158
  var {
218
159
  model
219
160
  } = this.props;
@@ -222,141 +163,33 @@ class AIOTable extends _react.Component {
222
163
  return false;
223
164
  }
224
165
 
166
+ let {
167
+ groups
168
+ } = this.state;
225
169
  this.index = {
226
170
  render: 0,
227
171
  real: 0
228
172
  };
229
173
  let rows;
230
174
  rows = this.fn.getRowsNested([...model], '_childs');
231
- rows = this.fn.getRowsBySort(rows, this.sorts);
232
- rows = this.fn.getRows(rows, this.columnDetails);
175
+ rows = this.fn.getRowsBySort(rows, sorts.filter(({
176
+ active = true
177
+ }) => active));
178
+ rows = this.fn.getRows(rows, freezeMode);
233
179
  rows = this.fn.getRootsByPaging(rows, this.index);
234
- rows = this.fn.getRootsByGroup(rows, this.groups);
180
+ rows = this.fn.getRootsByGroup(rows, groups.filter(({
181
+ active = true
182
+ }) => active));
235
183
  return this.fn.getRowsByRoots(rows);
236
184
  }
237
185
 
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
186
  handleIncomingProps() {
340
187
  let {
341
- columns,
342
188
  paging
343
189
  } = this.props;
344
190
  let {
345
- prevColumns,
346
191
  prevPaging
347
192
  } = 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
193
  let p = JSON.stringify(paging);
361
194
 
362
195
  if (p !== prevPaging) {
@@ -368,6 +201,17 @@ class AIOTable extends _react.Component {
368
201
  }
369
202
  }
370
203
 
204
+ getCellAttrs(row, column) {
205
+ let {
206
+ cellAttrs = {}
207
+ } = column;
208
+ return (typeof cellAttrs === 'function' ? cellAttrs(row) : cellAttrs) || {};
209
+ }
210
+
211
+ SetState(obj, caller) {
212
+ this.setState(obj);
213
+ }
214
+
371
215
  render() {
372
216
  this.handleIncomingProps();
373
217
  var {
@@ -381,13 +225,10 @@ class AIOTable extends _react.Component {
381
225
  style,
382
226
  attrs = {},
383
227
  cardTemplate,
384
- onChangeFilter,
385
228
  onSwap,
386
- padding,
387
229
  translate
388
230
  } = this.props;
389
231
  var {
390
- columns,
391
232
  paging
392
233
  } = this.state;
393
234
  this.rh = rowHeight;
@@ -395,11 +236,10 @@ class AIOTable extends _react.Component {
395
236
  this.th = toolbarHeight;
396
237
  this.rg = rowGap;
397
238
  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) : '';
239
+ let details = this.fn.getDetails();
401
240
  var context = { ...this.props,
402
241
  ...this.state,
242
+ details,
403
243
  onDrag: obj => this.dragStart = obj,
404
244
  onDrop: obj => {
405
245
  if (!this.dragStart) {
@@ -424,23 +264,23 @@ class AIOTable extends _react.Component {
424
264
  onSwap(this.dragStart, obj);
425
265
  }
426
266
  },
427
- onChangeFilter: onChangeFilter ? this.onChangeFilter.bind(this) : undefined,
428
- SetState: obj => this.setState(obj),
267
+ SetState: this.SetState.bind(this),
429
268
  onScroll: index => this.fn.onScroll(this.dom, index),
430
- groups: this.groups,
269
+ getCellAttrs: this.getCellAttrs.bind(this),
431
270
  fn: this.fn,
432
271
  rows: this.rows
433
272
  };
273
+ this.context = context;
274
+ let table = this.getTable(details);
434
275
  return /*#__PURE__*/_react.default.createElement(AioTableContext.Provider, {
435
276
  value: context
436
277
  }, /*#__PURE__*/_react.default.createElement("div", _extends({
437
278
  className: 'aio-table' + (className ? ' ' + className : '') + (rtl ? ' rtl' : ''),
438
279
  tabIndex: 0,
439
280
  ref: this.dom,
440
- style: { ...style,
441
- padding
281
+ style: { ...style
442
282
  }
443
- }, attrs), Toolbar, !cardTemplate && this.columnDetails.visibleColumns.length === 0 && this.fn.getLoading(), table, paging && /*#__PURE__*/_react.default.createElement(AIOTablePaging, {
283
+ }, attrs), /*#__PURE__*/_react.default.createElement(AIOTableToolbar, details), table, paging && /*#__PURE__*/_react.default.createElement(AIOTablePaging, {
444
284
  rtl: rtl,
445
285
  translate: translate,
446
286
  paging: paging,
@@ -463,11 +303,9 @@ AIOTable.defaultProps = {
463
303
  columns: [],
464
304
  toolbarHeight: 36,
465
305
  rowGap: 6,
466
- padding: 12,
467
- indent: 20,
306
+ indent: 16,
468
307
  translate: text => text,
469
308
  freezeSize: 300,
470
- sorts: [],
471
309
  groups: []
472
310
  };
473
311
 
@@ -485,52 +323,23 @@ class AIOTableToolbar extends _react.Component {
485
323
  this.setState({
486
324
  searchText: value
487
325
  });
488
- this.searchTimeout = setTimeout(() => {
489
- let {
490
- SetState
491
- } = this.context;
492
- let {
493
- search
494
- } = this.props;
495
-
496
- if (search) {
497
- SetState({
498
- searchText: value
499
- });
500
- } else {
501
- let {
502
- filterDictionary
503
- } = this.context;
504
- let {
505
- searchColumnIndex
506
- } = this.props;
507
- filterDictionary[searchColumnIndex] = {
508
- items: value ? [{
509
- operator: 'contain',
510
- value
511
- }] : [],
512
- booleanType: 'or'
513
- };
514
- SetState({
515
- filterDictionary
516
- });
517
- }
518
- }, time);
326
+ this.searchTimeout = setTimeout(() => this.context.SetState({
327
+ searchText: value
328
+ }), time);
519
329
  }
520
330
 
521
331
  getSearch() {
522
- var {
332
+ let {
523
333
  translate
524
334
  } = this.context;
525
- var {
526
- searchText
527
- } = this.state;
528
- var {
529
- searchColumnIndex,
335
+ let {
530
336
  search
531
337
  } = this.props;
338
+ let {
339
+ searchText
340
+ } = this.state;
532
341
 
533
- if (typeof searchColumnIndex !== 'number' && !search) {
342
+ if (!search) {
534
343
  return /*#__PURE__*/_react.default.createElement("div", {
535
344
  style: {
536
345
  flex: 1
@@ -560,110 +369,136 @@ class AIOTableToolbar extends _react.Component {
560
369
  }
561
370
 
562
371
  render() {
563
- var {
372
+ let {
564
373
  fn,
565
374
  rows,
566
375
  translate,
567
376
  rtl,
568
377
  toggleAllState,
569
- padding,
570
378
  toolbarItems = [],
571
379
  SetState,
572
- toolbarStyle = {}
573
- } = this.context;
574
- var {
575
- toggle,
576
- freeze,
577
- groupBy,
578
- sort,
380
+ toolbarAttrs = {},
579
381
  toggleAll,
580
- excelColumns
382
+ groups
383
+ } = this.context;
384
+ let {
385
+ toggleOptions,
386
+ freezeOptions,
387
+ groupOptions,
388
+ excelColumns,
389
+ sortOptions
581
390
  } = this.props;
582
- var buttonProps = {
391
+ let buttonProps = {
583
392
  type: 'select',
584
- caret: false,
585
393
  rtl,
394
+ caret: false,
586
395
  className: 'aio-table-toolbar-button',
587
- animate: true
396
+ animate: true,
397
+ popupAttrs: {
398
+ style: {
399
+ maxHeight: 500
400
+ }
401
+ }
588
402
  };
589
- let iconSize = 0.7;
403
+ let Sort, Toggle, Group, Freeze, Excel, ToggleAll;
404
+
405
+ if (sortOptions.length) {
406
+ let title = translate('Sort');
407
+ let props = { ...buttonProps,
408
+ options: sortOptions,
409
+ title,
410
+ key: 'sort',
411
+ text: aioTableGetSvg('sort'),
412
+ popupHeader: /*#__PURE__*/_react.default.createElement("div", {
413
+ className: "aio-table-popup-header"
414
+ }, title)
415
+ };
416
+ Sort = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
417
+ }
418
+
419
+ if (toggleOptions.length) {
420
+ let title = translate('Show Columns');
421
+ let props = { ...buttonProps,
422
+ options: toggleOptions,
423
+ title,
424
+ key: 'toggle',
425
+ text: aioTableGetSvg('eye'),
426
+ popupHeader: /*#__PURE__*/_react.default.createElement("div", {
427
+ className: "aio-table-popup-header"
428
+ }, title)
429
+ };
430
+ Toggle = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
431
+ }
432
+
433
+ if (groupOptions.length) {
434
+ let title = translate('Group By');
435
+ let props = { ...buttonProps,
436
+ options: groupOptions,
437
+ title,
438
+ key: 'group',
439
+ text: aioTableGetSvg('group', {
440
+ flip: rtl === true
441
+ }),
442
+ popupHeader: /*#__PURE__*/_react.default.createElement("div", {
443
+ className: "aio-table-popup-header"
444
+ }, title),
445
+ onSwap: (start, end, swap) => SetState({
446
+ groups: swap(groups, start, end)
447
+ })
448
+ };
449
+ Group = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
450
+ }
451
+
452
+ if (freezeOptions.length) {
453
+ let title = translate('Freeze');
454
+ let props = { ...buttonProps,
455
+ options: freezeOptions,
456
+ title,
457
+ key: 'freeze',
458
+ text: aioTableGetSvg('freeze'),
459
+ popupHeader: /*#__PURE__*/_react.default.createElement("div", {
460
+ className: "aio-table-popup-header"
461
+ }, title)
462
+ };
463
+ Freeze = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
464
+ }
465
+
466
+ if (toggleAll) {
467
+ let title = translate('Toggle All');
468
+ let props = { ...buttonProps,
469
+ title,
470
+ key: 'toggleAll',
471
+ type: 'button',
472
+ text: !toggleAllState ? aioTableGetSvg('toggleAllMinus') : aioTableGetSvg('toggleAllPlus'),
473
+ onclick: () => SetState(fn.getStateByToggleAll(rows))
474
+ };
475
+ ToggleAll = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
476
+ }
477
+
478
+ if (excelColumns.length) {
479
+ let title = translate('Export To Excel');
480
+ let props = { ...buttonProps,
481
+ title,
482
+ key: 'excel',
483
+ type: 'button',
484
+ text: aioTableGetSvg('excel'),
485
+ onClick: () => fn.exportToExcel(excelColumns, rows)
486
+ };
487
+ Excel = /*#__PURE__*/_react.default.createElement(_aioButton.default, props);
488
+ }
489
+
590
490
  return /*#__PURE__*/_react.default.createElement("div", {
591
- className: "aio-table-toolbar",
592
- style: {
593
- marginBottom: padding,
594
- ...toolbarStyle
491
+ className: 'aio-table-toolbar' + (toolbarAttrs.className ? ' ' + toolbarAttrs.className : ''),
492
+ style: { ...toolbarAttrs.style
595
493
  }
596
- }, toggleAll !== false && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
597
- key: "toggleAll"
598
- }, buttonProps, {
599
- type: "button",
600
- title: translate('Toggle All'),
601
- onClick: () => toggleAll(),
602
- text: !toggleAllState ? aioTableGetSvg('toggleAllMinus') : aioTableGetSvg('toggleAllPlus')
603
- })), excelColumns.length > 0 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
604
- key: "excel"
605
- }, buttonProps, {
606
- type: "button",
607
- title: translate('Export To Excel'),
608
- onClick: () => {
609
- fn.exportToExcel(excelColumns, rows);
610
- },
611
- text: aioTableGetSvg('excel')
612
- })), toolbarItems.map((o, i) => /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
494
+ }, ToggleAll, Excel, toolbarItems.map((o, i) => /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
613
495
  type: "button",
614
496
  rtl: rtl,
615
497
  className: "aio-table-toolbar-button",
616
498
  animate: true
617
499
  }, o, {
618
500
  key: 'ti' + i
619
- }))), this.getSearch(), groupBy.length > 1 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
620
- key: "groupby"
621
- }, buttonProps, {
622
- options: groupBy,
623
- title: translate('Group By'),
624
- text: aioTableGetSvg('group', {
625
- flip: rtl === true
626
- }),
627
- onSwap: (start, end, swap) => {
628
- let {
629
- groups
630
- } = this.context;
631
- SetState({
632
- groups: swap(groups, start - 1, end - 1)
633
- });
634
- }
635
- })), sort.length > 1 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
636
- key: "sort"
637
- }, buttonProps, {
638
- options: sort,
639
- title: translate('Sort'),
640
- text: aioTableGetSvg('sort'),
641
- onSwap: (start, end, swap) => {
642
- let {
643
- sorts
644
- } = this.context;
645
- SetState({
646
- sorts: swap(sorts, start - 1, end - 1)
647
- }); //-1 because title of items added to options[0]
648
- }
649
- })), toggle.length > 1 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
650
- key: "toggle"
651
- }, buttonProps, {
652
- text: aioTableGetSvg('eye'),
653
- options: toggle,
654
- title: translate('Show Columns'),
655
- popupStyle: {
656
- maxHeight: 400
657
- }
658
- })), freeze.length > 1 && /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
659
- key: "freeze"
660
- }, buttonProps, {
661
- text: aioTableGetSvg('freeze', {
662
- flip: rtl === true
663
- }),
664
- options: freeze,
665
- title: translate('Freeze Columns')
666
- })));
501
+ }))), this.getSearch(), Group, Sort, Toggle, Freeze);
667
502
  }
668
503
 
669
504
  }
@@ -875,15 +710,14 @@ class AIOTableUnit extends _react.Component {
875
710
 
876
711
  keyDown(e) {
877
712
  var {
878
- SetState,
879
- focused
713
+ SetState
880
714
  } = this.context;
881
715
 
882
716
  if (e.keyCode === 27) {
883
717
  (0, _jquery.default)('.aio-table-input').blur();
884
718
  SetState({
885
719
  focused: false
886
- });
720
+ }, 'keyDown');
887
721
  } else if ([37, 38, 39, 40].indexOf(e.keyCode) !== -1) {
888
722
  this.arrow(e);
889
723
  }
@@ -1038,7 +872,8 @@ class AIOTableUnit extends _react.Component {
1038
872
  fn,
1039
873
  focused,
1040
874
  SetState,
1041
- striped
875
+ striped,
876
+ getCellAttrs
1042
877
  } = this.context;
1043
878
  var {
1044
879
  rows,
@@ -1067,7 +902,7 @@ class AIOTableUnit extends _react.Component {
1067
902
  return /*#__PURE__*/_react.default.createElement(AIOTableGroup, {
1068
903
  tableIndex,
1069
904
  row: o,
1070
- columns,
905
+ columns: columns,
1071
906
  key: 'group' + i + '-' + tableIndex
1072
907
  });
1073
908
  }
@@ -1080,13 +915,14 @@ class AIOTableUnit extends _react.Component {
1080
915
  let row = o.row;
1081
916
  let cellId = i + '-' + j + '-' + tableIndex;
1082
917
  let inlineEdit = this.getPropValue(row, column, column.inlineEdit);
918
+ let attrs = getCellAttrs(row, column);
1083
919
  return /*#__PURE__*/_react.default.createElement(AIOTableCell, {
1084
920
  key: cellId,
1085
921
  attrs: {
1086
922
  'data-row-index': this.renderIndex,
1087
- 'data-col-index': column._renderIndex,
923
+ 'data-col-index': column.renderIndex,
1088
924
  'data-real-row-index': row._index,
1089
- 'data-real-col-index': column._index,
925
+ 'data-real-col-index': column.realIndex,
1090
926
  'data-child-index': row._childIndex,
1091
927
  'data-childs-length': row._childsLength,
1092
928
  'data-lavel': row._level,
@@ -1097,13 +933,26 @@ class AIOTableUnit extends _react.Component {
1097
933
  onDragOver: e => e.preventDefault(),
1098
934
  onDragStart: () => onDrag(row),
1099
935
  onClick: () => {
936
+ var {
937
+ focused,
938
+ SetState
939
+ } = this.context;
940
+
941
+ if (attrs.onClick) {
942
+ attrs.onClick(row);
943
+ }
944
+
1100
945
  if (!inlineEdit || focused === cellId) {
1101
946
  return;
1102
947
  }
1103
948
 
949
+ if (focused === false) {
950
+ setTimeout(() => fn.handleOutsideClick(), 5);
951
+ }
952
+
1104
953
  SetState({
1105
954
  focused: cellId
1106
- });
955
+ }, 'cellonClick');
1107
956
  setTimeout(() => (0, _jquery.default)('.aio-table-input:focus').select(), 10);
1108
957
  }
1109
958
  },
@@ -1125,18 +974,22 @@ class AIOTableUnit extends _react.Component {
1125
974
  _defineProperty(AIOTableUnit, "contextType", AioTableContext);
1126
975
 
1127
976
  class AIOTableTitle extends _react.Component {
1128
- getStyle() {
977
+ constructor(props) {
978
+ super(props);
979
+ this.dom = /*#__PURE__*/(0, _react.createRef)();
980
+ }
981
+
982
+ getStyle(style) {
1129
983
  let {
1130
984
  headerHeight,
1131
- columnGap,
1132
- titleStyle = {}
985
+ columnGap
1133
986
  } = this.context;
1134
987
  return {
1135
988
  height: headerHeight,
1136
989
  top: 0,
1137
990
  borderLeft: columnGap ? 'none' : undefined,
1138
991
  borderRight: columnGap ? 'none' : undefined,
1139
- ...titleStyle
992
+ ...style
1140
993
  };
1141
994
  }
1142
995
 
@@ -1161,10 +1014,8 @@ class AIOTableTitle extends _react.Component {
1161
1014
  (0, _jquery.default)(window).bind(touch ? 'touchend' : 'mouseup', _jquery.default.proxy(this.resizeUp, this));
1162
1015
  this.resizeDetails = {
1163
1016
  client: fn.getClient(e),
1164
- width: parseInt(gridTemplateColumns[column._renderIndex]),
1165
- renderIndex: column._renderIndex,
1166
- index: column._index,
1167
- minWidth: column.minWidth
1017
+ width: parseInt(gridTemplateColumns[column.renderIndex]),
1018
+ column
1168
1019
  };
1169
1020
  }
1170
1021
 
@@ -1181,19 +1032,18 @@ class AIOTableTitle extends _react.Component {
1181
1032
  var Client = fn.getClient(e);
1182
1033
  var {
1183
1034
  client,
1184
- renderIndex,
1185
1035
  width,
1186
- minWidth = '30px'
1036
+ column
1187
1037
  } = this.resizeDetails;
1188
1038
  var offset = Client[0] - client[0];
1189
1039
  let newWidth = width + offset * (rtl ? -1 : 1);
1190
1040
 
1191
- if (newWidth < parseInt(minWidth)) {
1192
- newWidth = parseInt(minWidth);
1041
+ if (newWidth < parseInt(column.minWidth || 36)) {
1042
+ newWidth = parseInt(column.minWidth || 36);
1193
1043
  }
1194
1044
 
1195
1045
  this.resizeDetails.newWidth = newWidth + 'px';
1196
- gridTemplateColumns[renderIndex] = this.resizeDetails.newWidth;
1046
+ gridTemplateColumns[column.renderIndex] = this.resizeDetails.newWidth;
1197
1047
  setStyle(gridTemplateColumns);
1198
1048
  }
1199
1049
 
@@ -1211,10 +1061,12 @@ class AIOTableTitle extends _react.Component {
1211
1061
  SetState
1212
1062
  } = this.context;
1213
1063
  var {
1214
- index,
1215
1064
  newWidth
1216
1065
  } = this.resizeDetails;
1217
- let column = { ...columns[index],
1066
+ let {
1067
+ column
1068
+ } = this.props;
1069
+ column = { ...column,
1218
1070
  width: newWidth
1219
1071
  };
1220
1072
 
@@ -1227,14 +1079,9 @@ class AIOTableTitle extends _react.Component {
1227
1079
  localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
1228
1080
  }
1229
1081
 
1082
+ columns = columns.map((c, i) => i === column.realIndex ? column : c);
1230
1083
  SetState({
1231
- columns: columns.map((c, i) => {
1232
- if (i === index) {
1233
- return column;
1234
- }
1235
-
1236
- return c;
1237
- })
1084
+ columns
1238
1085
  });
1239
1086
  }
1240
1087
 
@@ -1244,20 +1091,22 @@ class AIOTableTitle extends _react.Component {
1244
1091
  columnGap
1245
1092
  } = this.context;
1246
1093
  var {
1247
- getKeys,
1248
- padding = '36px'
1094
+ template
1249
1095
  } = column;
1250
- var keys = getKeys();
1096
+ let {
1097
+ padding = 36
1098
+ } = template;
1099
+ var keys = template.getKeys();
1251
1100
  return /*#__PURE__*/_react.default.createElement("div", {
1252
1101
  className: "aio-table-title aio-table-title-gantt",
1253
1102
  style: {
1254
- padding: `0 ${padding}`,
1103
+ padding: `0 ${+padding}px`,
1255
1104
  height: headerHeight,
1256
1105
  top: 0,
1257
1106
  borderLeft: columnGap ? 'none' : undefined,
1258
1107
  borderRight: columnGap ? 'none' : undefined
1259
1108
  },
1260
- key: column._index + 'title'
1109
+ key: column.realIndex + 'title'
1261
1110
  }, /*#__PURE__*/_react.default.createElement(_rRangeSlider.default, {
1262
1111
  start: 0,
1263
1112
  end: keys.length - 1,
@@ -1293,17 +1142,24 @@ class AIOTableTitle extends _react.Component {
1293
1142
  rtl
1294
1143
  } = this.context;
1295
1144
 
1296
- if (column.template === 'gantt') {
1145
+ if (column.template && column.template.type === 'gantt') {
1297
1146
  return this.getGanttTitle(column);
1298
1147
  }
1299
1148
 
1300
1149
  let title = typeof column.title === 'function' ? column.title() : column.title;
1150
+ let attrs = { ...this.context.titleAttrs,
1151
+ ...column.titleAttrs
1152
+ };
1153
+ let dataUniqId = 'aiotabletitle' + Math.round(Math.random() * 10000000);
1301
1154
  return /*#__PURE__*/_react.default.createElement("div", {
1302
- style: this.getStyle(),
1155
+ ref: this.dom,
1156
+ "data-uniq-id": dataUniqId,
1157
+ style: this.getStyle(attrs.style),
1303
1158
  draggable: false,
1304
- className: 'aio-table-title' + (column.titleClassName ? ' ' + column.titleClassName : '') + (isLast ? ' last-child' : '') + (rtl ? ' rtl' : ' ltr')
1159
+ className: 'aio-table-title' + (attrs.className ? ' ' + attrs.className : '') + (isLast ? ' last-child' : '') + (rtl ? ' rtl' : ' ltr')
1305
1160
  }, /*#__PURE__*/_react.default.createElement(AIOTableFilter, {
1306
- column: column
1161
+ column: column,
1162
+ dataUniqId: dataUniqId
1307
1163
  }), /*#__PURE__*/_react.default.createElement("div", {
1308
1164
  className: "aio-table-title-text",
1309
1165
  style: {
@@ -1311,8 +1167,8 @@ class AIOTableTitle extends _react.Component {
1311
1167
  cursor: column.movable === false ? undefined : 'move'
1312
1168
  },
1313
1169
  draggable: column.movable !== false,
1314
- onDragStart: () => onDragStart(column._index),
1315
- onDragOver: e => onDragOver(e, column._index),
1170
+ onDragStart: () => onDragStart(column.realIndex),
1171
+ onDragOver: e => onDragOver(e, column.realIndex),
1316
1172
  onDrop: () => onDrop(column)
1317
1173
  }, title), column.width !== 'auto' && /*#__PURE__*/_react.default.createElement("div", {
1318
1174
  className: "aio-table-resize",
@@ -1330,11 +1186,14 @@ class AIOTableTitle extends _react.Component {
1330
1186
  _defineProperty(AIOTableTitle, "contextType", AioTableContext);
1331
1187
 
1332
1188
  class AIOTableGroup extends _react.Component {
1333
- getStyle(columns) {
1189
+ getStyle() {
1334
1190
  let {
1335
1191
  rowHeight,
1336
1192
  fn
1337
1193
  } = this.context;
1194
+ let {
1195
+ columns
1196
+ } = this.props;
1338
1197
  return { ...fn.getFullCellStyle(columns),
1339
1198
  height: rowHeight
1340
1199
  };
@@ -1376,12 +1235,11 @@ class AIOTableGroup extends _react.Component {
1376
1235
  } = this.context;
1377
1236
  let {
1378
1237
  row,
1379
- tableIndex,
1380
- columns
1238
+ tableIndex
1381
1239
  } = this.props;
1382
1240
  return /*#__PURE__*/_react.default.createElement("div", {
1383
1241
  className: "aio-table-group",
1384
- style: this.getStyle(columns)
1242
+ style: this.getStyle()
1385
1243
  }, tableIndex !== 1 && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
1386
1244
  style: {
1387
1245
  width: indent * row._level,
@@ -1417,15 +1275,12 @@ class AIOTableCell extends _react.Component {
1417
1275
 
1418
1276
  getStyle(column, row) {
1419
1277
  var {
1420
- padding = '36px',
1421
1278
  template,
1422
1279
  minWidth = '30px'
1423
1280
  } = column;
1424
1281
  var {
1425
1282
  rowHeight,
1426
- getCellStyle = () => {
1427
- return {};
1428
- }
1283
+ getCellAttrs
1429
1284
  } = this.context;
1430
1285
  var style = {
1431
1286
  height: rowHeight,
@@ -1433,21 +1288,25 @@ class AIOTableCell extends _react.Component {
1433
1288
  minWidth
1434
1289
  };
1435
1290
 
1436
- if (column.template === 'gantt') {
1437
- style.padding = `0 ${padding}`;
1291
+ if (column.template && column.template.type === 'gantt') {
1292
+ style.padding = 0;
1438
1293
  }
1439
1294
 
1440
- let cellStyle = getCellStyle(row, column);
1295
+ let attrs = getCellAttrs(row, column);
1441
1296
  return { ...style,
1442
- ...cellStyle
1297
+ ...attrs.style
1443
1298
  };
1444
1299
  }
1445
1300
 
1446
1301
  getClassName(row, column) {
1302
+ let {
1303
+ getCellAttrs
1304
+ } = this.context;
1447
1305
  var className = 'aio-table-cell';
1448
1306
  let {
1449
1307
  striped
1450
1308
  } = this.props;
1309
+ let attrs = getCellAttrs(row, column);
1451
1310
 
1452
1311
  if (striped) {
1453
1312
  className += ' striped';
@@ -1461,8 +1320,8 @@ class AIOTableCell extends _react.Component {
1461
1320
  className += ' aio-table-cell-gantt';
1462
1321
  }
1463
1322
 
1464
- if (column.className) {
1465
- className += ' ' + column.className;
1323
+ if (attrs.className) {
1324
+ className += ' ' + attrs.className;
1466
1325
  }
1467
1326
 
1468
1327
  if (column.inlineEdit) {
@@ -1495,9 +1354,7 @@ class AIOTableCell extends _react.Component {
1495
1354
  } = this.context;
1496
1355
  let icon;
1497
1356
 
1498
- if (!row._childsLength) {
1499
- icon = '';
1500
- } else if (row._opened) {
1357
+ if (row._opened) {
1501
1358
  icon = aioTableGetSvg('chevronDown');
1502
1359
  } else {
1503
1360
  icon = aioTableGetSvg('chevronRight', {
@@ -1507,68 +1364,137 @@ class AIOTableCell extends _react.Component {
1507
1364
 
1508
1365
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
1509
1366
  className: "aio-table-toggle",
1510
- onClick: () => fn.toggleRow(row)
1367
+ onClick: () => fn.toggleRow(row),
1368
+ style: {
1369
+ opacity: row._childsLength ? 1 : 0
1370
+ }
1511
1371
  }, icon), /*#__PURE__*/_react.default.createElement("div", {
1512
1372
  className: "aio-table-cell-gap"
1513
1373
  }));
1514
1374
  }
1515
1375
 
1516
- getContent(row, column, value) {
1517
- var {
1518
- focused,
1519
- fn
1520
- } = this.context;
1521
- let {
1522
- inlineEdit
1523
- } = this.props;
1524
- var content = '';
1525
- let template = typeof column.template === 'function' ? column.template(row, column) : column.template;
1376
+ splitNumber(num) {
1377
+ if (!num) {
1378
+ return num;
1379
+ }
1526
1380
 
1527
- if (template && template.type === 'slider') {
1528
- content = fn.getSliderCell(template);
1529
- } else if (template && template.type === 'options') {
1530
- content = fn.getOptionsCell(template);
1531
- } else if (template && template.type === 'gantt') {
1532
- content = fn.getGanttCell(row, template);
1533
- } else if (template && inlineEdit) {
1534
- content = focused ? this.getInput(row, column) : template;
1535
- } else if (template) {
1536
- content = template;
1537
- } else if (inlineEdit) {
1538
- content = this.getInput(row, column);
1539
- } else {
1540
- content = value;
1381
+ let str = num.toString();
1382
+ let dotIndex = str.indexOf('.');
1383
+
1384
+ if (dotIndex !== -1) {
1385
+ str = str.slice(0, dotIndex);
1541
1386
  }
1542
1387
 
1543
- if (column.subText) {
1544
- let subText;
1388
+ let res = '';
1389
+ let index = 0;
1545
1390
 
1546
- try {
1547
- subText = column.subText(row);
1548
- } catch {
1549
- subText = '';
1550
- }
1391
+ for (let i = str.length - 1; i >= 0; i--) {
1392
+ res = str[i] + res;
1551
1393
 
1552
- return /*#__PURE__*/_react.default.createElement("div", {
1553
- className: "aio-table-cell-has-subtext"
1554
- }, /*#__PURE__*/_react.default.createElement("div", {
1555
- className: "aio-table-cell-uptext"
1556
- }, content), /*#__PURE__*/_react.default.createElement("div", {
1557
- className: "aio-table-cell-subtext"
1558
- }, subText));
1394
+ if (index === 2) {
1395
+ index = 0;
1396
+
1397
+ if (i > 0) {
1398
+ res = ',' + res;
1399
+ }
1400
+ } else {
1401
+ index++;
1402
+ }
1559
1403
  }
1560
1404
 
1561
- return content;
1405
+ return res;
1562
1406
  }
1563
1407
 
1564
- async changeCell(value) {
1408
+ getContentByTemplate(row, column, value) {
1565
1409
  let {
1566
- row,
1410
+ fn
1411
+ } = this.context;
1412
+ let template = typeof column.template === 'function' ? column.template(row, column) : column.template;
1413
+
1414
+ if (!template) {
1415
+ return value;
1416
+ }
1417
+
1418
+ if (!template.type) {
1419
+ return template;
1420
+ }
1421
+
1422
+ if (template.type === 'slider') {
1423
+ return fn.getSliderCell(template, value);
1424
+ }
1425
+
1426
+ if (template.type === 'options') {
1427
+ return fn.getOptionsCell(template, row);
1428
+ }
1429
+
1430
+ if (template.type === 'split') {
1431
+ let newValue = this.splitNumber(value);
1432
+
1433
+ if (template.editValue) {
1434
+ newValue = template.editValue(newValue);
1435
+ }
1436
+
1437
+ return newValue;
1438
+ }
1439
+
1440
+ if (template.type === 'gantt') {
1441
+ return fn.getGanttCell(row, template);
1442
+ }
1443
+ }
1444
+
1445
+ getContent(row, column, value) {
1446
+ let {
1447
+ focused
1448
+ } = this.context;
1449
+ let {
1450
+ inlineEdit
1451
+ } = this.props;
1452
+ let template = this.getContentByTemplate(row, column, value);
1453
+ var content = '';
1454
+
1455
+ if (inlineEdit && focused) {
1456
+ content = this.getInput(row, column);
1457
+ } else {
1458
+ content = template;
1459
+ }
1460
+
1461
+ if (column.subText) {
1462
+ let subText;
1463
+
1464
+ try {
1465
+ subText = column.subText(row);
1466
+ } catch {
1467
+ subText = '';
1468
+ }
1469
+
1470
+ return /*#__PURE__*/_react.default.createElement("div", {
1471
+ className: "aio-table-cell-has-subtext"
1472
+ }, /*#__PURE__*/_react.default.createElement("div", {
1473
+ style: {
1474
+ flex: 1
1475
+ }
1476
+ }), /*#__PURE__*/_react.default.createElement("div", {
1477
+ className: "aio-table-cell-uptext"
1478
+ }, content), /*#__PURE__*/_react.default.createElement("div", {
1479
+ className: "aio-table-cell-subtext"
1480
+ }, subText), /*#__PURE__*/_react.default.createElement("div", {
1481
+ style: {
1482
+ flex: 1
1483
+ }
1484
+ }));
1485
+ }
1486
+
1487
+ return content;
1488
+ }
1489
+
1490
+ async changeCell(value) {
1491
+ let {
1492
+ row,
1567
1493
  column,
1568
1494
  inlineEdit
1569
1495
  } = this.props;
1570
1496
  let {
1571
- setCellValue
1497
+ fn
1572
1498
  } = this.context;
1573
1499
  let res;
1574
1500
  this.setState({
@@ -1577,8 +1503,8 @@ class AIOTableCell extends _react.Component {
1577
1503
 
1578
1504
  if (inlineEdit.onChange) {
1579
1505
  res = await inlineEdit.onChange(row, value);
1580
- } else {
1581
- res = await this.context.onChange(setCellValue(row, column.field, value));
1506
+ } else if (typeof column.getValue === 'string') {
1507
+ res = await this.context.onChange(fn.setCellValue(row, column.getValue, value));
1582
1508
  }
1583
1509
 
1584
1510
  this.setState({
@@ -1589,7 +1515,7 @@ class AIOTableCell extends _react.Component {
1589
1515
 
1590
1516
  getInput(row, column) {
1591
1517
  let {
1592
- getCellValue
1518
+ fn
1593
1519
  } = this.context;
1594
1520
  let {
1595
1521
  attrs,
@@ -1606,7 +1532,7 @@ class AIOTableCell extends _react.Component {
1606
1532
  } = this.state;
1607
1533
 
1608
1534
  if (getValue) {
1609
- value = getCellValue(row, getValue, column.field);
1535
+ value = fn.getCellValue(row, getValue);
1610
1536
  }
1611
1537
 
1612
1538
  if (disabled(row)) {
@@ -1629,7 +1555,7 @@ class AIOTableCell extends _react.Component {
1629
1555
  className: 'aio-table-input-container'
1630
1556
  }, /*#__PURE__*/_react.default.createElement("input", _extends({}, props, {
1631
1557
  style: {
1632
- textAlign: column.justify ? 'center' : undefined
1558
+ textAlign: column.justify || type === 'number' ? 'center' : undefined
1633
1559
  },
1634
1560
  onChange: e => this.setState({
1635
1561
  value: e.target.value
@@ -1766,10 +1692,12 @@ class AIOTableCell extends _react.Component {
1766
1692
  }
1767
1693
 
1768
1694
  getProps(row, column, content) {
1769
- let title = column.getTooltip ? column.getTooltip(row) : typeof content === 'string' ? content : undefined;
1695
+ let attrs = this.context.getCellAttrs(row, column);
1696
+ let title = typeof content === 'string' ? content : undefined;
1770
1697
  return {
1771
1698
  ref: this.dom,
1772
1699
  title,
1700
+ ...attrs,
1773
1701
  style: this.getStyle(column, row),
1774
1702
  className: this.getClassName(row, column)
1775
1703
  };
@@ -1802,6 +1730,11 @@ class AIOTableCell extends _react.Component {
1802
1730
  loading
1803
1731
  } = this.state;
1804
1732
  let content = this.getContent(row, column, value);
1733
+
1734
+ if (column.affix) {
1735
+ content = content + ' ' + column.affix;
1736
+ }
1737
+
1805
1738
  let cell;
1806
1739
 
1807
1740
  if (loading) {
@@ -1850,31 +1783,47 @@ class AIOTableCell extends _react.Component {
1850
1783
  _defineProperty(AIOTableCell, "contextType", AioTableContext);
1851
1784
 
1852
1785
  class AIOTableFilter extends _react.Component {
1853
- change(obj) {
1786
+ constructor(...args) {
1787
+ super(...args);
1788
+
1789
+ _defineProperty(this, "dom", /*#__PURE__*/(0, _react.createRef)());
1790
+ }
1791
+
1792
+ async change(obj) {
1854
1793
  let {
1855
- onChangeFilter,
1856
- filterDictionary,
1857
- SetState
1794
+ SetState,
1795
+ columns
1858
1796
  } = this.context;
1859
1797
  let {
1860
1798
  column
1861
1799
  } = this.props;
1862
- filterDictionary[column._index] = { ...filterDictionary[column._index],
1863
- ...obj
1800
+ column = { ...column,
1801
+ filter: { ...column.filter,
1802
+ ...obj
1803
+ }
1864
1804
  };
1805
+ let approve = true;
1865
1806
 
1866
- if (onChangeFilter) {
1867
- onChangeFilter(filterDictionary);
1807
+ if (column.filter.onChange) {
1808
+ let loading = (0, _jquery.default)(this.dom.current).parents('.aio-table').find('.aio-table-main-loading');
1809
+ loading.css({
1810
+ display: 'flex'
1811
+ });
1812
+ approve = await newFilter.onChange(column.filter);
1813
+ loading.css({
1814
+ display: 'none'
1815
+ });
1868
1816
  }
1869
1817
 
1870
- SetState({
1871
- filterDictionary
1872
- });
1818
+ if (approve !== false) {
1819
+ SetState({
1820
+ columns: columns.map(o => o.realIndex === column.realIndex ? column : o)
1821
+ });
1822
+ }
1873
1823
  }
1874
1824
 
1875
1825
  render() {
1876
1826
  var {
1877
- filterDictionary,
1878
1827
  rtl,
1879
1828
  translate
1880
1829
  } = this.context;
@@ -1886,35 +1835,40 @@ class AIOTableFilter extends _react.Component {
1886
1835
  return null;
1887
1836
  }
1888
1837
 
1889
- if (!filterDictionary[column._index]) {
1890
- return null;
1891
- }
1892
-
1893
1838
  let {
1894
- items,
1895
- booleanType
1896
- } = filterDictionary[column._index];
1897
- let {
1898
- type
1839
+ items = [],
1840
+ booleanType = 'or',
1841
+ type = 'text'
1899
1842
  } = column.filter;
1900
1843
  let icon = items.length ? aioTableGetSvg('filterActive', {
1901
1844
  className: 'has-filter'
1902
1845
  }) : aioTableGetSvg('filter');
1903
1846
  return /*#__PURE__*/_react.default.createElement("div", {
1904
- className: "aio-table-filter-icon"
1847
+ className: "aio-table-filter-icon",
1848
+ ref: this.dom,
1849
+ onClick: () => {
1850
+ (0, _jquery.default)('.aio-table-title').css({
1851
+ zIndex: 100
1852
+ });
1853
+ (0, _jquery.default)(`[data-uniq-id = ${this.props.dataUniqId}]`).css({
1854
+ zIndex: 1000
1855
+ });
1856
+ }
1905
1857
  }, /*#__PURE__*/_react.default.createElement(_aioButton.default, {
1906
1858
  type: "button",
1907
1859
  rtl: rtl,
1908
1860
  caret: false,
1909
1861
  openRelatedTo: ".aio-table",
1910
1862
  text: icon,
1911
- popOver: () => /*#__PURE__*/_react.default.createElement(AIOTableFilterPopup, {
1912
- translate,
1913
- type,
1914
- items,
1915
- booleanType,
1916
- onChange: obj => this.change(obj)
1917
- })
1863
+ popOver: () => {
1864
+ return /*#__PURE__*/_react.default.createElement(AIOTableFilterPopup, {
1865
+ translate,
1866
+ type,
1867
+ items,
1868
+ booleanType,
1869
+ onChange: obj => this.change(obj)
1870
+ });
1871
+ }
1918
1872
  }));
1919
1873
  }
1920
1874
 
@@ -2010,7 +1964,7 @@ class AIOTableFilterItem extends _react.Component {
2010
1964
  getOptions(type, translate) {
2011
1965
  let options = [];
2012
1966
 
2013
- if (type !== 'number') {
1967
+ if (type !== 'number' && type !== 'date') {
2014
1968
  options.push( /*#__PURE__*/_react.default.createElement("option", {
2015
1969
  key: "contain",
2016
1970
  value: "contain"
@@ -2091,7 +2045,8 @@ class AIOTableFilterItem extends _react.Component {
2091
2045
  function ATFN({
2092
2046
  getProps,
2093
2047
  getState,
2094
- setState
2048
+ setState,
2049
+ getContext
2095
2050
  }) {
2096
2051
  let $$ = {
2097
2052
  fixPersianAndArabicNumbers(str) {
@@ -2121,9 +2076,9 @@ function ATFN({
2121
2076
  for (let j = 0; j < columns.length; j++) {
2122
2077
  let {
2123
2078
  title,
2124
- _index
2079
+ realIndex
2125
2080
  } = columns[j];
2126
- let res = row._values[_index];
2081
+ let res = row._values[realIndex];
2127
2082
  obj[title] = res !== undefined ? $$.fixPersianAndArabicNumbers(res) : "";
2128
2083
  }
2129
2084
 
@@ -2185,13 +2140,14 @@ function ATFN({
2185
2140
  document.body.removeChild(link);
2186
2141
  },
2187
2142
 
2188
- getSliderCell({
2189
- colors = ['#eee', 'dodgerblue'],
2190
- start = 0,
2191
- end = 100,
2192
- value,
2193
- editValue = value => value
2194
- }) {
2143
+ getSliderCell(template, val) {
2144
+ let {
2145
+ colors = ['#eee', 'dodgerblue'],
2146
+ start = 0,
2147
+ end = 100,
2148
+ value = val,
2149
+ editValue = value => value
2150
+ } = template;
2195
2151
  let {
2196
2152
  rowHeight,
2197
2153
  rtl
@@ -2251,7 +2207,8 @@ function ATFN({
2251
2207
  },
2252
2208
 
2253
2209
  getOptionsCell({
2254
- options = []
2210
+ options,
2211
+ row
2255
2212
  }) {
2256
2213
  return /*#__PURE__*/_react.default.createElement(_aioButton.default, {
2257
2214
  type: "select",
@@ -2265,12 +2222,8 @@ function ATFN({
2265
2222
  }) => {
2266
2223
  return {
2267
2224
  text,
2268
- before: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, icon, /*#__PURE__*/_react.default.createElement("div", {
2269
- style: {
2270
- width: 6
2271
- }
2272
- })),
2273
- onClick
2225
+ before: icon,
2226
+ onClick: () => onClick(row)
2274
2227
  };
2275
2228
  })
2276
2229
  });
@@ -2288,24 +2241,9 @@ function ATFN({
2288
2241
  getProgress = () => false,
2289
2242
  getText = () => false,
2290
2243
  getStart,
2291
- getEnd
2244
+ getEnd,
2245
+ padding = 36
2292
2246
  } = template;
2293
-
2294
- if (typeof getStart !== 'function') {
2295
- console.error('aio table => gantt column => column getStart property is not a function');
2296
- return '';
2297
- }
2298
-
2299
- if (typeof getEnd !== 'function') {
2300
- console.error('aio table => gantt column => column getEnd property is not a function');
2301
- return '';
2302
- }
2303
-
2304
- if (typeof getKeys !== 'function') {
2305
- console.error('aio table => gantt column => column getKeys property is not a function');
2306
- return '';
2307
- }
2308
-
2309
2247
  let keys = getKeys();
2310
2248
 
2311
2249
  if (!Array.isArray(keys)) {
@@ -2313,15 +2251,20 @@ function ATFN({
2313
2251
  return '';
2314
2252
  }
2315
2253
 
2316
- let color = getColor(row);
2317
- let backgroundColor = getBackgroundColor(row);
2318
- let progress = getProgress(row);
2319
- let text = getText(row);
2320
- let startIndex = keys.indexOf(getStart(row));
2321
- let endIndex = keys.indexOf(getEnd(row));
2322
- 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%)`;
2254
+ let color = $$.getCellValue(row, getColor);
2255
+ let backgroundColor = $$.getCellValue(row, getBackgroundColor);
2256
+ let progress = $$.getCellValue(row, getProgress);
2257
+ let text = $$.getCellValue(row, getText);
2258
+ let startIndex = keys.indexOf($$.getCellValue(row, getStart));
2259
+ let endIndex = keys.indexOf($$.getCellValue(row, getEnd));
2260
+ 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%)`;
2323
2261
  let flags = getFlags();
2324
2262
  return /*#__PURE__*/_react.default.createElement(_rRangeSlider.default, {
2263
+ attrs: {
2264
+ style: {
2265
+ padding: `0 ${+padding}px`
2266
+ }
2267
+ },
2325
2268
  start: 0,
2326
2269
  editValue: value => keys[value],
2327
2270
  end: keys.length - 1,
@@ -2372,25 +2315,41 @@ function ATFN({
2372
2315
  },
2373
2316
 
2374
2317
  handleOutsideClick() {
2375
- (0, _jquery.default)(window).bind('click', e => {
2376
- var {
2377
- focused
2378
- } = getState();
2318
+ (0, _jquery.default)(window).unbind('click', $$.outSideClick);
2319
+ (0, _jquery.default)(window).bind('click', $$.outSideClick);
2320
+ },
2379
2321
 
2380
- if (focused === false) {
2381
- return;
2382
- }
2322
+ outSideClick(e) {
2323
+ let {
2324
+ focused
2325
+ } = getState();
2383
2326
 
2384
- var target = (0, _jquery.default)(e.target);
2327
+ if (focused === false) {
2328
+ return;
2329
+ }
2385
2330
 
2386
- if (target.parents('.aio-table-cell').length !== 0 || target.hasClass('aio-table-cell')) {
2387
- return;
2388
- }
2331
+ let target = (0, _jquery.default)(e.target);
2389
2332
 
2390
- setState({
2391
- focused: false
2392
- });
2393
- });
2333
+ if (target.hasClass('aio-table-cell')) {
2334
+ return;
2335
+ }
2336
+
2337
+ if (target.parents('.aio-table-input-container').length) {
2338
+ return;
2339
+ }
2340
+
2341
+ if (target.parents('.aio-table-cell-content').length) {
2342
+ return;
2343
+ }
2344
+
2345
+ if (target.parents('.aio-table-cell').length) {
2346
+ return;
2347
+ }
2348
+
2349
+ (0, _jquery.default)(window).unbind('click', $$.outSideClick);
2350
+ setState({
2351
+ focused: false
2352
+ }, 'outsideClick');
2394
2353
  },
2395
2354
 
2396
2355
  getCardRowCount() {
@@ -2488,25 +2447,6 @@ function ATFN({
2488
2447
  $$['scroll' + index] = false;
2489
2448
  },
2490
2449
 
2491
- getGroupDictionaty() {
2492
- let {
2493
- id
2494
- } = getProps();
2495
-
2496
- if (id === undefined) {
2497
- return {};
2498
- }
2499
-
2500
- let groupDictionary = localStorage.getItem('aio table group' + id);
2501
-
2502
- if (groupDictionary === null || groupDictionary === undefined) {
2503
- localStorage.setItem('aio table group' + id, '{}');
2504
- return {};
2505
- } else {
2506
- return JSON.parse(groupDictionary);
2507
- }
2508
- },
2509
-
2510
2450
  getOpenDictionary() {
2511
2451
  let {
2512
2452
  id
@@ -2541,319 +2481,423 @@ function ATFN({
2541
2481
  return parseInt(list.map(o => o.length === 1 ? '0' + o : o).join(''));
2542
2482
  },
2543
2483
 
2544
- getSorts(toolbar) {
2484
+ setCellValue: (row, getValue, value) => {
2485
+ //row is used in eval
2545
2486
  let {
2546
- onChangeSort
2487
+ model
2547
2488
  } = getProps();
2548
- let {
2549
- sorts,
2550
- columns = [],
2551
- getCellValue
2552
- } = getState();
2553
- let sortTitles = sorts.map(o => o.title);
2489
+ let evalText;
2554
2490
 
2555
- for (let i = 0; i < columns.length; i++) {
2556
- if (!columns[i].sort) {
2557
- continue;
2491
+ if (typeof value === 'string') {
2492
+ evalText = `row.${getValue} = "${value}"`;
2493
+ } else {
2494
+ evalText = 'row.' + getValue + ' = ' + JSON.stringify(value);
2495
+ }
2496
+
2497
+ eval(evalText);
2498
+ return model;
2499
+ },
2500
+ getCellValue: (row, getValue) => {
2501
+ try {
2502
+ if (typeof getValue === 'function') {
2503
+ return getValue(row);
2558
2504
  }
2559
2505
 
2560
- if (sortTitles.indexOf(columns[i].title) !== -1) {
2561
- continue;
2506
+ if (typeof getValue === 'string') {
2507
+ let result;
2508
+ eval('result = row.' + getValue);
2509
+ return result;
2562
2510
  }
2563
2511
 
2564
- columns[i]._addedToSorts = true;
2565
- let column = columns[i];
2512
+ return;
2513
+ } catch {
2514
+ return;
2515
+ }
2516
+ },
2566
2517
 
2567
- if (column.sort === true) {
2568
- column.sort = {};
2569
- }
2518
+ async onChangeSort(obj, colIndex) {
2519
+ let {
2520
+ columns
2521
+ } = getState();
2522
+ columns = [...columns];
2523
+ let column = { ...columns[colIndex]
2524
+ };
2525
+ column.sort = { ...column.sort,
2526
+ ...obj
2527
+ };
2528
+ let newColumns = columns.map((o, i) => i === colIndex ? column : o);
2529
+ let approve = true;
2570
2530
 
2531
+ if (column.sort.onChange) {
2571
2532
  let {
2572
- sort
2573
- } = columns[i];
2574
- let a = sort.title || column.title || '';
2575
- let title = typeof a === 'function' ? a() : a;
2576
- let getValue = sort.getValue || column.getValue;
2577
- let field = sort.field || column.field;
2578
- let {
2579
- toggle = true,
2580
- dir = 'inc',
2581
2533
  active = true,
2582
- type
2583
- } = sort;
2584
- sorts.push({
2585
- title,
2586
- dir,
2534
+ dir = 'inc'
2535
+ } = column.sort;
2536
+ approve = await column.sort.onChange({
2587
2537
  active,
2588
- toggle,
2589
- getValue,
2590
- type,
2591
- field
2538
+ dir
2592
2539
  });
2593
2540
  }
2594
2541
 
2595
- let Sorts = sorts.map(o => {
2596
- return { ...o,
2597
- onChangeDir: () => {
2598
- o.dir = o.dir === 'dec' ? 'inc' : 'dec';
2599
- setState({
2600
- sorts
2601
- });
2542
+ if (approve !== false) {
2543
+ setState({
2544
+ columns: newColumns
2545
+ });
2546
+ }
2547
+ },
2602
2548
 
2603
- if (onChangeSort) {
2604
- onChangeSort(Sorts.filter(o => o.active !== false));
2605
- }
2606
- },
2607
- onChangeActive: () => {
2608
- o.active = o.active === undefined ? true : o.active;
2609
- o.active = !o.active;
2610
- setState({
2611
- sorts
2612
- });
2549
+ getSorts({
2550
+ column,
2551
+ sorts,
2552
+ sortOptions,
2553
+ columnTitle,
2554
+ colIndex
2555
+ }) {
2556
+ let {
2557
+ sort
2558
+ } = column;
2559
+ let {
2560
+ title = columnTitle || '',
2561
+ getValue = column.getValue,
2562
+ type,
2563
+ active = true,
2564
+ toggle = true,
2565
+ dir = 'inc',
2566
+ onChange
2567
+ } = sort;
2613
2568
 
2614
- if (onChangeSort) {
2615
- onChangeSort(Sorts.filter(o => o.active !== false));
2616
- }
2569
+ if (type === 'date') {
2570
+ getValue = row => {
2571
+ let {
2572
+ sort
2573
+ } = column;
2574
+ let {
2575
+ getValue = column.getValue
2576
+ } = sort;
2577
+ let value = $$.getCellValue(row, getValue);
2578
+
2579
+ if (typeof value !== 'string') {
2580
+ return 0;
2617
2581
  }
2582
+
2583
+ return $$.getDateNumber(value);
2618
2584
  };
2619
- });
2620
- let result = [];
2585
+ }
2621
2586
 
2622
- for (let i = 0; i < Sorts.length; i++) {
2623
- let sort = Sorts[i];
2624
- let {
2625
- getValue,
2626
- dir = 'inc',
2627
- title,
2628
- active = true,
2629
- toggle = true,
2630
- type,
2631
- onChangeDir,
2632
- onChangeActive,
2633
- field
2634
- } = sort;
2587
+ sorts.push({
2588
+ title,
2589
+ dir,
2590
+ active,
2591
+ toggle,
2592
+ getValue,
2593
+ type,
2594
+ onChange
2595
+ });
2635
2596
 
2636
- if (!title) {
2637
- console.error('aio table => missing sort title property');
2638
- continue;
2639
- }
2597
+ if (toggle) {
2598
+ sortOptions.push({
2599
+ text: title,
2600
+ checked: !!active,
2601
+ onClick: () => $$.onChangeSort({
2602
+ active: !active
2603
+ }, colIndex),
2604
+ after: /*#__PURE__*/_react.default.createElement("div", {
2605
+ style: {
2606
+ width: '30px',
2607
+ display: 'flex',
2608
+ justifyContent: 'flex-end'
2609
+ }
2610
+ }, aioTableGetSvg(dir === 'dec' ? 'arrowDown' : 'arrowUp', {
2611
+ onClick: e => {
2612
+ e.stopPropagation();
2613
+ $$.onChangeSort({
2614
+ dir: dir === 'dec' ? 'inc' : 'dec'
2615
+ }, colIndex);
2616
+ }
2617
+ }))
2618
+ });
2619
+ }
2620
+ },
2640
2621
 
2641
- if (active === true) {
2642
- if (type === 'date') {
2643
- let newGetValue = row => {
2644
- let value = getCellValue(row, getValue, field);
2622
+ getToggles(obj) {
2623
+ let {
2624
+ column,
2625
+ toggleOptions,
2626
+ colIndex,
2627
+ columnTitle
2628
+ } = obj;
2629
+ let {
2630
+ columns
2631
+ } = getState();
2632
+ toggleOptions.push({
2633
+ text: columnTitle,
2634
+ checked: column.show !== false,
2635
+ onClick: () => {
2636
+ //change columns imutable(prevent change columns directly)
2637
+ let column = { ...obj.column,
2638
+ show: !obj.column.show
2639
+ };
2645
2640
 
2646
- if (typeof value !== 'string') {
2647
- return 0;
2641
+ if (column.storageKey) {
2642
+ column = { ...column,
2643
+ _storageObj: { ...column._storageObj,
2644
+ show: column.show
2648
2645
  }
2649
-
2650
- return $$.getDateNumber(value);
2651
2646
  };
2652
-
2653
- result.push({
2654
- getValue: row => newGetValue(row),
2655
- dir
2656
- });
2657
- } else {
2658
- result.push({
2659
- getValue,
2660
- dir
2661
- });
2647
+ localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
2662
2648
  }
2663
- }
2664
2649
 
2665
- if (toggle) {
2666
- toolbar.show = true;
2667
- toolbar.sort.push({
2668
- text: title,
2669
- checked: active === true,
2670
- after: /*#__PURE__*/_react.default.createElement("div", {
2671
- style: {
2672
- width: '30px',
2673
- display: 'flex',
2674
- justifyContent: 'flex-end'
2675
- }
2676
- }, aioTableGetSvg(dir === 'dec' ? 'arrowDown' : 'arrowUp', {
2677
- onClick: e => {
2678
- e.stopPropagation();
2679
- onChangeDir();
2680
- }
2681
- })),
2682
- onClick: () => onChangeActive()
2650
+ setState({
2651
+ columns: columns.map((o, i) => i === column.realIndex ? column : o)
2683
2652
  });
2684
2653
  }
2685
- }
2686
-
2687
- return result;
2654
+ });
2688
2655
  },
2689
2656
 
2690
- getGroups(toolbar) {
2691
- var {
2692
- id
2693
- } = getProps();
2694
- var {
2695
- groups,
2696
- groupDictionary
2697
- } = getState();
2698
- let result = [];
2699
-
2700
- for (let i = 0; i < groups.length; i++) {
2701
- let group = groups[i];
2702
- let {
2703
- title,
2704
- active = true,
2705
- toggle = true
2706
- } = group;
2707
-
2708
- if (!title) {
2709
- console.error('aio table => missing group title property');
2710
- continue;
2711
- }
2712
-
2713
- groupDictionary[title] = groupDictionary[title] === undefined ? active : groupDictionary[title];
2714
-
2715
- if (groupDictionary[title]) {
2716
- result.push(group);
2717
- }
2718
-
2719
- if (toggle) {
2720
- toolbar.show = true;
2721
- toolbar.groupBy.push({
2722
- text: title,
2723
- checked: groupDictionary[title],
2724
- onClick: () => {
2725
- groupDictionary[title] = !groupDictionary[title];
2657
+ getFreezes({
2658
+ column,
2659
+ colIndex,
2660
+ columnTitle,
2661
+ freezeOptions,
2662
+ freezeColumns,
2663
+ unFreezeColumns
2664
+ }) {
2665
+ (column.freeze ? freezeColumns : unFreezeColumns).push(column);
2726
2666
 
2727
- if (id) {
2728
- localStorage.setItem('aio table group' + id, JSON.stringify(groupDictionary));
2729
- }
2667
+ if (!column.toggleFreeze) {
2668
+ return;
2669
+ }
2730
2670
 
2731
- setState({
2732
- groupDictionary
2733
- });
2734
- }
2671
+ freezeOptions.push({
2672
+ text: columnTitle,
2673
+ checked: column.freeze === true,
2674
+ onClick: () => {
2675
+ let {
2676
+ columns
2677
+ } = getState();
2678
+ columns = [...columns];
2679
+ let column = { ...columns[colIndex]
2680
+ };
2681
+ column.freeze = !column.freeze;
2682
+ setState({
2683
+ columns: columns.map((o, i) => i === colIndex ? column : o)
2735
2684
  });
2736
2685
  }
2737
- }
2738
-
2739
- return result;
2686
+ });
2740
2687
  },
2741
2688
 
2742
- setColumnByStorage(column) {
2743
- if (column.storageKey && !column._readStorage) {
2689
+ updateColumnByStorage(column) {
2690
+ let {
2691
+ storageKey,
2692
+ _readStorage
2693
+ } = column;
2694
+
2695
+ if (storageKey && !_readStorage) {
2744
2696
  column._readStorage = true;
2745
2697
  let storageStr = localStorage.getItem('aio-table-column-storage-' + column.storageKey);
2698
+ let storageObj;
2746
2699
 
2747
2700
  if (!storageStr || storageStr === null) {
2748
- column._storageObj = {};
2749
- localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
2701
+ storageObj = {};
2702
+ localStorage.setItem('aio-table-column-storage-' + column.storageKey, '{}');
2750
2703
  } else {
2751
- column._storageObj = JSON.parse(storageStr);
2704
+ storageObj = JSON.parse(storageStr);
2752
2705
  }
2753
2706
 
2754
- if (column._storageObj.show !== undefined) {
2755
- column.show = column._storageObj.show;
2756
- } else {
2757
- column.show = column.show === undefined ? true : column.show;
2707
+ if (storageObj.show !== undefined) {
2708
+ column.show = storageObj.show;
2758
2709
  }
2759
2710
 
2760
- if (column._storageObj.width !== undefined) {
2761
- column.width = column._storageObj.width;
2762
- } else {
2763
- column.width = column.width || 'auto';
2711
+ if (storageObj.width !== undefined) {
2712
+ column.width = storageObj.width;
2764
2713
  }
2765
- } else {
2766
- column.show = column.show === undefined ? true : column.show;
2767
- column.width = column.width || 'auto';
2714
+
2715
+ column._storageObj = storageObj;
2768
2716
  }
2769
2717
  },
2770
2718
 
2771
- getFreezes(index, columnDetails, toolbar) {
2719
+ getDetails() {
2772
2720
  let {
2773
- columns
2721
+ columns,
2722
+ groups
2774
2723
  } = getState();
2775
- let column = columns[index];
2724
+ columns = [...columns];
2725
+ let sorts = [];
2726
+ let freezeColumns = [],
2727
+ unFreezeColumns = [],
2728
+ freezeOptions = [],
2729
+ sortOptions = [],
2730
+ toggleOptions = [],
2731
+ groupOptions = [];
2732
+ let excelColumns = [],
2733
+ visibleColumns = [],
2734
+ search = false;
2735
+ let groupTitles = groups.map(o => o.title);
2736
+ let renderIndex = 0;
2776
2737
 
2777
- if (column.freeze) {
2778
- columnDetails.freeze.active = true;
2779
- columnDetails.freeze.freezeColumns.push(column);
2780
- } else {
2781
- columnDetails.freeze.unFreezeColumns.push(column);
2782
- }
2783
-
2784
- if (column.toggleFreeze) {
2785
- toolbar.show = true;
2786
- toolbar.freeze.push({
2787
- text: column.title,
2788
- checked: column.freeze === true,
2789
- onClick: () => {
2790
- let state = columns[index].freeze === true ? true : false;
2791
- let column = { ...columns[index],
2792
- freeze: !state
2793
- };
2794
- setState({
2795
- columns: columns.map((c, i) => {
2796
- if (i === index) {
2797
- return column;
2798
- }
2799
-
2800
- return c;
2801
- })
2738
+ for (let i = 0; i < columns.length; i++) {
2739
+ columns[i].realIndex = i;
2740
+
2741
+ if (columns[i].sort === true) {
2742
+ columns[i].sort = {};
2743
+ }
2744
+
2745
+ if (columns[i].filter === true) {
2746
+ columns[i].filter = {
2747
+ items: [],
2748
+ booleanType: 'or',
2749
+ type: 'text'
2750
+ };
2751
+ }
2752
+
2753
+ if (columns[i].group === true) {
2754
+ columns[i].group = {};
2755
+ }
2756
+
2757
+ columns[i].width = columns[i].width || 'auto';
2758
+ let column = { ...columns[i]
2759
+ };
2760
+ column.realIndex = i;
2761
+ $$.updateColumnByStorage(column);
2762
+ let {
2763
+ title: columnTitle,
2764
+ show = true,
2765
+ sort,
2766
+ toggleShow,
2767
+ excel
2768
+ } = column;
2769
+ columnTitle = typeof columnTitle === 'function' ? columnTitle() : columnTitle;
2770
+ column.show = typeof show === 'function' ? show() : show;
2771
+
2772
+ if (column.search) {
2773
+ search = true;
2774
+ }
2775
+
2776
+ if (column.group && groupTitles.indexOf(columnTitle) === -1) {
2777
+ let {
2778
+ title = columnTitle,
2779
+ active = true,
2780
+ toggle = true,
2781
+ storageKey = column.storageKey,
2782
+ getValue = column.getValue
2783
+ } = column.group;
2784
+ groups.push({
2785
+ title,
2786
+ active,
2787
+ toggle,
2788
+ storageKey,
2789
+ getValue
2790
+ });
2791
+ }
2792
+
2793
+ if (column.show) {
2794
+ column.renderIndex = renderIndex;
2795
+ columns[i].renderIndex = renderIndex;
2796
+ renderIndex++;
2797
+ visibleColumns.push(column);
2798
+
2799
+ if (excel) {
2800
+ excelColumns.push(column);
2801
+ }
2802
+
2803
+ if (sort) {
2804
+ $$.getSorts({
2805
+ column,
2806
+ columnTitle,
2807
+ sorts,
2808
+ sortOptions,
2809
+ colIndex: i
2802
2810
  });
2803
2811
  }
2804
- });
2812
+
2813
+ $$.getFreezes({
2814
+ column,
2815
+ colIndex: i,
2816
+ columnTitle,
2817
+ freezeOptions,
2818
+ freezeColumns,
2819
+ unFreezeColumns
2820
+ });
2821
+ }
2822
+
2823
+ if (toggleShow) {
2824
+ $$.getToggles({
2825
+ column,
2826
+ columnTitle,
2827
+ toggleOptions,
2828
+ colIndex: i
2829
+ });
2830
+ }
2805
2831
  }
2832
+
2833
+ $$.getGroups(groupOptions);
2834
+ return {
2835
+ sorts,
2836
+ sortOptions,
2837
+ freezeColumns,
2838
+ unFreezeColumns,
2839
+ freezeOptions,
2840
+ toggleOptions,
2841
+ groupOptions,
2842
+ excelColumns,
2843
+ columns: visibleColumns,
2844
+ search
2845
+ };
2806
2846
  },
2807
2847
 
2808
- getToggleShows(index, toolbar) {
2809
- let {
2810
- columns
2848
+ getGroups(groupOptions) {
2849
+ var {
2850
+ groups
2811
2851
  } = getState();
2812
- let column = columns[index];
2813
- let {
2814
- show,
2815
- storageKey
2816
- } = column;
2817
- let title = typeof column.title === 'function' ? column.title() : column.title;
2818
- toolbar.show = true;
2819
- toolbar.toggle.push({
2820
- text: title,
2821
- checked: show !== false,
2822
- onClick: () => {
2823
- //change columns imutable(prevent change columns directly)
2824
- let {
2825
- columns
2826
- } = getState();
2827
- let column = columns[index];
2828
- let newColumn;
2829
2852
 
2830
- if (storageKey) {
2831
- let newShow = !column._storageObj.show;
2832
- let newStorageObj = { ...column._storageObj,
2833
- show: newShow
2834
- };
2835
- newColumn = { ...column,
2836
- _storageObj: newStorageObj,
2837
- show: newShow
2838
- };
2839
- localStorage.setItem('aio-table-column-storage-' + newColumn.storageKey, JSON.stringify(newColumn._storageObj));
2853
+ for (let i = 0; i < groups.length; i++) {
2854
+ let group = groups[i];
2855
+ let {
2856
+ title,
2857
+ active = true,
2858
+ toggle = true,
2859
+ storageKey,
2860
+ _readStorage
2861
+ } = group;
2862
+
2863
+ if (storageKey && !_readStorage) {
2864
+ group._readStorage = true;
2865
+ let storageActive = localStorage.getItem('aio table group' + storageKey);
2866
+
2867
+ if (storageActive === null) {
2868
+ storageActive = true;
2869
+ localStorage.setItem('aio table group' + storageKey, JSON.stringify(storageAtive));
2840
2870
  } else {
2841
- newColumn = { ...column,
2842
- show: !column.show
2843
- };
2871
+ storageActive = JSON.parse(storageActive);
2844
2872
  }
2845
2873
 
2846
- setState({
2847
- columns: columns.map((c, i) => {
2848
- if (i === index) {
2849
- return newColumn;
2874
+ active = storageActive;
2875
+ }
2876
+
2877
+ group.active = active;
2878
+
2879
+ if (toggle) {
2880
+ groupOptions.push({
2881
+ text: title,
2882
+ checked: active === true,
2883
+ onClick: () => {
2884
+ let {
2885
+ groups
2886
+ } = getState();
2887
+ let group = groups[i];
2888
+ group.active = !group.active;
2889
+
2890
+ if (storageKey) {
2891
+ localStorage.setItem('aio table group' + storageKey, JSON.stringify(group.active));
2850
2892
  }
2851
2893
 
2852
- return c;
2853
- })
2894
+ setState({
2895
+ groups
2896
+ });
2897
+ }
2854
2898
  });
2855
2899
  }
2856
- });
2900
+ }
2857
2901
  },
2858
2902
 
2859
2903
  isContain(text, subtext) {
@@ -3018,13 +3062,12 @@ function ATFN({
3018
3062
 
3019
3063
  getFilterResult(column, value) {
3020
3064
  let {
3021
- filterDictionary
3022
- } = getState();
3023
- let filters = filterDictionary[column._index].items;
3065
+ items = [],
3066
+ booleanType = 'or'
3067
+ } = column.filter;
3024
3068
 
3025
- if (filters.length) {
3026
- let booleanType = filterDictionary[column._index].booleanType;
3027
- return $$['getFilterResult_' + booleanType](filters, value);
3069
+ if (items.length) {
3070
+ return $$['getFilterResult_' + booleanType](items, value);
3028
3071
  }
3029
3072
 
3030
3073
  return true;
@@ -3093,31 +3136,6 @@ function ATFN({
3093
3136
  }));
3094
3137
  },
3095
3138
 
3096
- getBodyStyle(Toolbar) {
3097
- let {
3098
- paging
3099
- } = getState();
3100
- let {
3101
- padding
3102
- } = getProps();
3103
- var def = padding,
3104
- top = 0;
3105
-
3106
- if (paging) {
3107
- def += 36;
3108
- }
3109
-
3110
- if (Toolbar !== null) {
3111
- def += 36;
3112
- top += 36;
3113
- }
3114
-
3115
- return {
3116
- height: `calc(100% - ${def}px)`,
3117
- top
3118
- };
3119
- },
3120
-
3121
3139
  toggleRow(row) {
3122
3140
  var {
3123
3141
  openDictionary
@@ -3141,21 +3159,15 @@ function ATFN({
3141
3159
  });
3142
3160
  },
3143
3161
 
3144
- getRow(row, columnDetails) {
3162
+ getRow(row) {
3145
3163
  let {
3146
- visibleColumns: columns,
3147
- freeze
3148
- } = columnDetails;
3149
- var {
3150
- onChangeFilter,
3151
- search
3152
- } = getProps();
3153
- let {
3154
- filterDictionary,
3155
- searchText,
3156
- getCellValue
3164
+ searchText
3157
3165
  } = getState();
3166
+ let {
3167
+ columns
3168
+ } = getContext().details;
3158
3169
  row._values = {};
3170
+ let searchShow;
3159
3171
  let show = true,
3160
3172
  lastColumn,
3161
3173
  isThereAutoColumn = false,
@@ -3164,43 +3176,33 @@ function ATFN({
3164
3176
  unFreezeCells = [];
3165
3177
 
3166
3178
  for (let i = 0; i < columns.length; i++) {
3167
- let column = columns[i],
3168
- value = getCellValue(row, column.getValue, column.field);
3169
- row._values[column._index] = value;
3170
- filterDictionary[column._index] = filterDictionary[column._index] || {
3171
- items: [],
3172
- booleanType: 'or'
3173
- };
3179
+ let column = columns[i];
3180
+ let value = $$.getCellValue(row, column.getValue);
3181
+ row._values[column.realIndex] = value;
3174
3182
 
3175
- if (show && search) {
3176
- if (searchText === '') {
3177
- show = true;
3178
- } else {
3179
- try {
3180
- show = search(row, searchText);
3181
- } catch {
3182
- show = false;
3183
- }
3183
+ if (show && column.search && searchText) {
3184
+ if (searchShow === undefined) {
3185
+ searchShow = false;
3184
3186
  }
3187
+
3188
+ searchShow = searchShow || JSON.stringify(value).toLowerCase().indexOf(searchText.toLowerCase()) !== -1;
3185
3189
  }
3186
3190
 
3187
- if (show && !onChangeFilter) {
3191
+ if (show && column.filter && !column.filter.onChange) {
3188
3192
  show = show && $$.getFilterResult(column, value);
3189
3193
  }
3190
3194
 
3191
3195
  let obj = {
3192
- key: row._index + ',' + column._index,
3196
+ key: row._index + ',' + column.realIndex,
3193
3197
  column,
3194
3198
  value,
3195
3199
  freeze: column.freeze
3196
3200
  };
3197
3201
 
3198
- if (freeze.active) {
3202
+ if ($$.freezeMode) {
3199
3203
  if (column.freeze) {
3200
- column._renderIndex = freezeCells.length;
3201
3204
  freezeCells.push(obj);
3202
3205
  } else {
3203
- column._renderIndex = unFreezeCells.length;
3204
3206
  lastColumn = column;
3205
3207
  unFreezeCells.push(obj);
3206
3208
 
@@ -3209,7 +3211,6 @@ function ATFN({
3209
3211
  }
3210
3212
  }
3211
3213
  } else {
3212
- column._renderIndex = i;
3213
3214
  cells.push(obj);
3214
3215
  lastColumn = column;
3215
3216
 
@@ -3219,7 +3220,7 @@ function ATFN({
3219
3220
  }
3220
3221
  }
3221
3222
 
3222
- row._show = show;
3223
+ row._show = show && searchShow !== false;
3223
3224
 
3224
3225
  if (show) {
3225
3226
  let parents = row._getParents();
@@ -3291,29 +3292,6 @@ function ATFN({
3291
3292
  };
3292
3293
  },
3293
3294
 
3294
- showColumnRelativeGroups(column) {
3295
- var {
3296
- groups
3297
- } = getState();
3298
-
3299
- if (!groups) {
3300
- return true;
3301
- }
3302
-
3303
- if (!groups.length) {
3304
- return true;
3305
- }
3306
-
3307
- if (!column.groupName) {
3308
- return true;
3309
- }
3310
-
3311
- var {
3312
- groupDictionary
3313
- } = getState();
3314
- return groupDictionary[column.groupName] !== true;
3315
- },
3316
-
3317
3295
  getClient(e) {
3318
3296
  return getState().touch ? [e.changedTouches[0].clientX, e.changedTouches[0].clientY] : [e.clientX, e.clientY];
3319
3297
  },
@@ -3372,11 +3350,11 @@ function ATFN({
3372
3350
  let childs = [];
3373
3351
 
3374
3352
  if (getRowChilds) {
3375
- childs = getRowChilds(row) || [];
3353
+ childs = $$.getCellValue(row, getRowChilds) || [];
3376
3354
  row._childsLength = childs.length;
3377
3355
  }
3378
3356
 
3379
- let Row = $$.getRow(row, $$.columnDetails);
3357
+ let Row = $$.getRow(row);
3380
3358
 
3381
3359
  if (row._level === 0) {
3382
3360
  rows.push([]);
@@ -3428,27 +3406,24 @@ function ATFN({
3428
3406
  },
3429
3407
 
3430
3408
  getRowsBySort(rows, sorts) {
3431
- let {
3432
- getCellValue
3433
- } = getState();
3434
-
3435
3409
  if (!sorts.length) {
3436
3410
  return rows;
3437
3411
  }
3438
3412
 
3439
- if (getProps().onChangeSort) {
3440
- return rows;
3441
- }
3442
-
3443
3413
  return rows.sort((a, b) => {
3444
3414
  for (let i = 0; i < sorts.length; i++) {
3445
3415
  let {
3446
3416
  getValue,
3447
3417
  dir,
3448
- field
3418
+ onChange
3449
3419
  } = sorts[i];
3450
- let aValue = getCellValue(a, getValue, field),
3451
- bValue = getCellValue(b, getValue, field);
3420
+
3421
+ if (onChange) {
3422
+ continue;
3423
+ }
3424
+
3425
+ let aValue = $$.getCellValue(a, getValue),
3426
+ bValue = $$.getCellValue(b, getValue);
3452
3427
 
3453
3428
  if (aValue < bValue) {
3454
3429
  return -1 * (dir === 'dec' ? -1 : 1);
@@ -3458,21 +3433,19 @@ function ATFN({
3458
3433
  return 1 * (dir === 'dec' ? -1 : 1);
3459
3434
  }
3460
3435
 
3461
- if (i !== sorts.length - 1) {
3462
- continue;
3436
+ if (i === sorts.length - 1) {
3437
+ return 0;
3463
3438
  }
3464
-
3465
- return 0;
3466
3439
  }
3467
3440
 
3468
3441
  return 0;
3469
3442
  });
3470
3443
  },
3471
3444
 
3472
- getRows(model, columnDetails) {
3445
+ getRows(model, freezeMode) {
3473
3446
  let rows = [];
3474
3447
  $$.realIndex = 0;
3475
- $$.columnDetails = columnDetails;
3448
+ $$.freezeMode = freezeMode;
3476
3449
  $$.getRowsReq(model, rows, 0, [], []);
3477
3450
  let result = [];
3478
3451
 
@@ -3535,8 +3508,7 @@ function ATFN({
3535
3508
  }
3536
3509
 
3537
3510
  var {
3538
- groupsOpen,
3539
- getCellValue
3511
+ groupsOpen
3540
3512
  } = getState();
3541
3513
 
3542
3514
  function msf(obj, _level, parents) {
@@ -3568,7 +3540,7 @@ function ATFN({
3568
3540
  for (let i = 0; i < roots.length; i++) {
3569
3541
  let root = roots[i];
3570
3542
  var obj = newModel;
3571
- let values = groups.map(group => getCellValue(root[0].row, group.getValue, group.field));
3543
+ let values = groups.map(group => $$.getCellValue(root[0].row, group.getValue, group.field));
3572
3544
 
3573
3545
  for (let j = 0; j < values.length; j++) {
3574
3546
  let value = values[j];
@@ -3629,6 +3601,7 @@ function ATFN({
3629
3601
  };
3630
3602
  return {
3631
3603
  exportToExcel: $$.exportToExcel,
3604
+ getDetails: $$.getDetails,
3632
3605
  getSliderCell: $$.getSliderCell,
3633
3606
  getOptionsCell: $$.getOptionsCell,
3634
3607
  getGanttCell: $$.getGanttCell,
@@ -3636,23 +3609,17 @@ function ATFN({
3636
3609
  onScroll: $$.onScroll,
3637
3610
  getCardRowCount: $$.getCardRowCount,
3638
3611
  getOpenDictionary: $$.getOpenDictionary,
3639
- getGroupDictionaty: $$.getGroupDictionaty,
3640
- getSorts: $$.getSorts,
3641
3612
  getRowsBySort: $$.getRowsBySort,
3642
3613
  getGroups: $$.getGroups,
3643
3614
  getRootsByGroup: $$.getRootsByGroup,
3644
3615
  setColumnByStorage: $$.setColumnByStorage,
3645
- getFreezes: $$.getFreezes,
3646
- getToggleShows: $$.getToggleShows,
3647
3616
  getFilterResult: $$.getFilterResult,
3648
3617
  getLoading: $$.getLoading,
3649
3618
  cubes2: $$.cubes2,
3650
- getBodyStyle: $$.getBodyStyle,
3651
3619
  getRow: $$.getRow,
3652
3620
  getRowById: $$.getRowById,
3653
3621
  getClient: $$.getClient,
3654
3622
  getStateByToggleAll: $$.getStateByToggleAll,
3655
- showColumnRelativeGroups: $$.showColumnRelativeGroups,
3656
3623
  getRootsByPaging: $$.getRootsByPaging,
3657
3624
  getRowsReq: $$.getRowsReq,
3658
3625
  getRowsNested: $$.getRowsNested,
@@ -3661,7 +3628,10 @@ function ATFN({
3661
3628
  getRowsByRoots: $$.getRowsByRoots,
3662
3629
  toggleRow: $$.toggleRow,
3663
3630
  getFullCellStyle: $$.getFullCellStyle,
3664
- getNoData: $$.getNoData
3631
+ getNoData: $$.getNoData,
3632
+ getSortsFromColumns: $$.getSortsFromColumns,
3633
+ getCellValue: $$.getCellValue,
3634
+ setCellValue: $$.setCellValue
3665
3635
  };
3666
3636
  }
3667
3637