aio-table 6.3.0 → 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 +27 -7
  2. package/index.js +899 -904
  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,
@@ -461,15 +301,11 @@ class AIOTable extends _react.Component {
461
301
  exports.default = AIOTable;
462
302
  AIOTable.defaultProps = {
463
303
  columns: [],
464
- headerHeight: 36,
465
- rowHeight: 36,
466
304
  toolbarHeight: 36,
467
305
  rowGap: 6,
468
- padding: 12,
469
- indent: 20,
306
+ indent: 16,
470
307
  translate: text => text,
471
308
  freezeSize: 300,
472
- sorts: [],
473
309
  groups: []
474
310
  };
475
311
 
@@ -487,52 +323,23 @@ class AIOTableToolbar extends _react.Component {
487
323
  this.setState({
488
324
  searchText: value
489
325
  });
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);
326
+ this.searchTimeout = setTimeout(() => this.context.SetState({
327
+ searchText: value
328
+ }), time);
521
329
  }
522
330
 
523
331
  getSearch() {
524
- var {
332
+ let {
525
333
  translate
526
334
  } = this.context;
527
- var {
528
- searchText
529
- } = this.state;
530
- var {
531
- searchColumnIndex,
335
+ let {
532
336
  search
533
337
  } = this.props;
338
+ let {
339
+ searchText
340
+ } = this.state;
534
341
 
535
- if (typeof searchColumnIndex !== 'number' && !search) {
342
+ if (!search) {
536
343
  return /*#__PURE__*/_react.default.createElement("div", {
537
344
  style: {
538
345
  flex: 1
@@ -562,110 +369,136 @@ class AIOTableToolbar extends _react.Component {
562
369
  }
563
370
 
564
371
  render() {
565
- var {
372
+ let {
566
373
  fn,
567
374
  rows,
568
375
  translate,
569
376
  rtl,
570
377
  toggleAllState,
571
- padding,
572
378
  toolbarItems = [],
573
379
  SetState,
574
- toolbarStyle = {}
575
- } = this.context;
576
- var {
577
- toggle,
578
- freeze,
579
- groupBy,
580
- sort,
380
+ toolbarAttrs = {},
581
381
  toggleAll,
582
- excelColumns
382
+ groups
383
+ } = this.context;
384
+ let {
385
+ toggleOptions,
386
+ freezeOptions,
387
+ groupOptions,
388
+ excelColumns,
389
+ sortOptions
583
390
  } = this.props;
584
- var buttonProps = {
391
+ let buttonProps = {
585
392
  type: 'select',
586
- caret: false,
587
393
  rtl,
394
+ caret: false,
588
395
  className: 'aio-table-toolbar-button',
589
- animate: true
396
+ animate: true,
397
+ popupAttrs: {
398
+ style: {
399
+ maxHeight: 500
400
+ }
401
+ }
590
402
  };
591
- 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
+
592
490
  return /*#__PURE__*/_react.default.createElement("div", {
593
- className: "aio-table-toolbar",
594
- style: {
595
- marginBottom: padding,
596
- ...toolbarStyle
491
+ className: 'aio-table-toolbar' + (toolbarAttrs.className ? ' ' + toolbarAttrs.className : ''),
492
+ style: { ...toolbarAttrs.style
597
493
  }
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({
494
+ }, ToggleAll, Excel, toolbarItems.map((o, i) => /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
615
495
  type: "button",
616
496
  rtl: rtl,
617
497
  className: "aio-table-toolbar-button",
618
498
  animate: true
619
499
  }, o, {
620
500
  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
- })));
501
+ }))), this.getSearch(), Group, Sort, Toggle, Freeze);
669
502
  }
670
503
 
671
504
  }
@@ -830,6 +663,7 @@ class AIOTableUnit extends _react.Component {
830
663
  } = this.props;
831
664
  return columns.map((column, i) => {
832
665
  return /*#__PURE__*/_react.default.createElement(AIOTableTitle, {
666
+ isLast: i === columns.length - 1,
833
667
  key: 'title' + i,
834
668
  column: column,
835
669
  gridTemplateColumns: this.gridTemplateColumns,
@@ -876,15 +710,14 @@ class AIOTableUnit extends _react.Component {
876
710
 
877
711
  keyDown(e) {
878
712
  var {
879
- SetState,
880
- focused
713
+ SetState
881
714
  } = this.context;
882
715
 
883
716
  if (e.keyCode === 27) {
884
717
  (0, _jquery.default)('.aio-table-input').blur();
885
718
  SetState({
886
719
  focused: false
887
- });
720
+ }, 'keyDown');
888
721
  } else if ([37, 38, 39, 40].indexOf(e.keyCode) !== -1) {
889
722
  this.arrow(e);
890
723
  }
@@ -991,7 +824,17 @@ class AIOTableUnit extends _react.Component {
991
824
  let rows;
992
825
 
993
826
  if (search) {
994
- rows = this.props.rows.filter(o => search(o.row, searchText));
827
+ rows = this.props.rows.filter(o => {
828
+ if (searchText === '') {
829
+ return true;
830
+ }
831
+
832
+ try {
833
+ return search(o.row, searchText);
834
+ } catch {
835
+ return false;
836
+ }
837
+ });
995
838
  } else {
996
839
  rows = this.props.rows;
997
840
  }
@@ -1029,7 +872,8 @@ class AIOTableUnit extends _react.Component {
1029
872
  fn,
1030
873
  focused,
1031
874
  SetState,
1032
- striped
875
+ striped,
876
+ getCellAttrs
1033
877
  } = this.context;
1034
878
  var {
1035
879
  rows,
@@ -1058,7 +902,7 @@ class AIOTableUnit extends _react.Component {
1058
902
  return /*#__PURE__*/_react.default.createElement(AIOTableGroup, {
1059
903
  tableIndex,
1060
904
  row: o,
1061
- columns,
905
+ columns: columns,
1062
906
  key: 'group' + i + '-' + tableIndex
1063
907
  });
1064
908
  }
@@ -1071,13 +915,14 @@ class AIOTableUnit extends _react.Component {
1071
915
  let row = o.row;
1072
916
  let cellId = i + '-' + j + '-' + tableIndex;
1073
917
  let inlineEdit = this.getPropValue(row, column, column.inlineEdit);
918
+ let attrs = getCellAttrs(row, column);
1074
919
  return /*#__PURE__*/_react.default.createElement(AIOTableCell, {
1075
920
  key: cellId,
1076
921
  attrs: {
1077
922
  'data-row-index': this.renderIndex,
1078
- 'data-col-index': column._renderIndex,
923
+ 'data-col-index': column.renderIndex,
1079
924
  'data-real-row-index': row._index,
1080
- 'data-real-col-index': column._index,
925
+ 'data-real-col-index': column.realIndex,
1081
926
  'data-child-index': row._childIndex,
1082
927
  'data-childs-length': row._childsLength,
1083
928
  'data-lavel': row._level,
@@ -1088,13 +933,26 @@ class AIOTableUnit extends _react.Component {
1088
933
  onDragOver: e => e.preventDefault(),
1089
934
  onDragStart: () => onDrag(row),
1090
935
  onClick: () => {
936
+ var {
937
+ focused,
938
+ SetState
939
+ } = this.context;
940
+
941
+ if (attrs.onClick) {
942
+ attrs.onClick(row);
943
+ }
944
+
1091
945
  if (!inlineEdit || focused === cellId) {
1092
946
  return;
1093
947
  }
1094
948
 
949
+ if (focused === false) {
950
+ setTimeout(() => fn.handleOutsideClick(), 5);
951
+ }
952
+
1095
953
  SetState({
1096
954
  focused: cellId
1097
- });
955
+ }, 'cellonClick');
1098
956
  setTimeout(() => (0, _jquery.default)('.aio-table-input:focus').select(), 10);
1099
957
  }
1100
958
  },
@@ -1116,18 +974,22 @@ class AIOTableUnit extends _react.Component {
1116
974
  _defineProperty(AIOTableUnit, "contextType", AioTableContext);
1117
975
 
1118
976
  class AIOTableTitle extends _react.Component {
1119
- getStyle() {
977
+ constructor(props) {
978
+ super(props);
979
+ this.dom = /*#__PURE__*/(0, _react.createRef)();
980
+ }
981
+
982
+ getStyle(style) {
1120
983
  let {
1121
984
  headerHeight,
1122
- columnGap,
1123
- titleStyle = {}
985
+ columnGap
1124
986
  } = this.context;
1125
987
  return {
1126
988
  height: headerHeight,
1127
989
  top: 0,
1128
990
  borderLeft: columnGap ? 'none' : undefined,
1129
991
  borderRight: columnGap ? 'none' : undefined,
1130
- ...titleStyle
992
+ ...style
1131
993
  };
1132
994
  }
1133
995
 
@@ -1152,10 +1014,8 @@ class AIOTableTitle extends _react.Component {
1152
1014
  (0, _jquery.default)(window).bind(touch ? 'touchend' : 'mouseup', _jquery.default.proxy(this.resizeUp, this));
1153
1015
  this.resizeDetails = {
1154
1016
  client: fn.getClient(e),
1155
- width: parseInt(gridTemplateColumns[column._renderIndex]),
1156
- renderIndex: column._renderIndex,
1157
- index: column._index,
1158
- minWidth: column.minWidth
1017
+ width: parseInt(gridTemplateColumns[column.renderIndex]),
1018
+ column
1159
1019
  };
1160
1020
  }
1161
1021
 
@@ -1172,19 +1032,18 @@ class AIOTableTitle extends _react.Component {
1172
1032
  var Client = fn.getClient(e);
1173
1033
  var {
1174
1034
  client,
1175
- renderIndex,
1176
1035
  width,
1177
- minWidth = '30px'
1036
+ column
1178
1037
  } = this.resizeDetails;
1179
1038
  var offset = Client[0] - client[0];
1180
1039
  let newWidth = width + offset * (rtl ? -1 : 1);
1181
1040
 
1182
- if (newWidth < parseInt(minWidth)) {
1183
- newWidth = parseInt(minWidth);
1041
+ if (newWidth < parseInt(column.minWidth || 36)) {
1042
+ newWidth = parseInt(column.minWidth || 36);
1184
1043
  }
1185
1044
 
1186
1045
  this.resizeDetails.newWidth = newWidth + 'px';
1187
- gridTemplateColumns[renderIndex] = this.resizeDetails.newWidth;
1046
+ gridTemplateColumns[column.renderIndex] = this.resizeDetails.newWidth;
1188
1047
  setStyle(gridTemplateColumns);
1189
1048
  }
1190
1049
 
@@ -1202,10 +1061,12 @@ class AIOTableTitle extends _react.Component {
1202
1061
  SetState
1203
1062
  } = this.context;
1204
1063
  var {
1205
- index,
1206
1064
  newWidth
1207
1065
  } = this.resizeDetails;
1208
- let column = { ...columns[index],
1066
+ let {
1067
+ column
1068
+ } = this.props;
1069
+ column = { ...column,
1209
1070
  width: newWidth
1210
1071
  };
1211
1072
 
@@ -1218,14 +1079,9 @@ class AIOTableTitle extends _react.Component {
1218
1079
  localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
1219
1080
  }
1220
1081
 
1082
+ columns = columns.map((c, i) => i === column.realIndex ? column : c);
1221
1083
  SetState({
1222
- columns: columns.map((c, i) => {
1223
- if (i === index) {
1224
- return column;
1225
- }
1226
-
1227
- return c;
1228
- })
1084
+ columns
1229
1085
  });
1230
1086
  }
1231
1087
 
@@ -1235,20 +1091,22 @@ class AIOTableTitle extends _react.Component {
1235
1091
  columnGap
1236
1092
  } = this.context;
1237
1093
  var {
1238
- getKeys,
1239
- padding = '36px'
1094
+ template
1240
1095
  } = column;
1241
- var keys = getKeys();
1096
+ let {
1097
+ padding = 36
1098
+ } = template;
1099
+ var keys = template.getKeys();
1242
1100
  return /*#__PURE__*/_react.default.createElement("div", {
1243
1101
  className: "aio-table-title aio-table-title-gantt",
1244
1102
  style: {
1245
- padding: `0 ${padding}`,
1103
+ padding: `0 ${+padding}px`,
1246
1104
  height: headerHeight,
1247
1105
  top: 0,
1248
1106
  borderLeft: columnGap ? 'none' : undefined,
1249
1107
  borderRight: columnGap ? 'none' : undefined
1250
1108
  },
1251
- key: column._index + 'title'
1109
+ key: column.realIndex + 'title'
1252
1110
  }, /*#__PURE__*/_react.default.createElement(_rRangeSlider.default, {
1253
1111
  start: 0,
1254
1112
  end: keys.length - 1,
@@ -1277,20 +1135,31 @@ class AIOTableTitle extends _react.Component {
1277
1135
  column,
1278
1136
  onDragStart,
1279
1137
  onDragOver,
1280
- onDrop
1138
+ onDrop,
1139
+ isLast
1281
1140
  } = this.props;
1141
+ let {
1142
+ rtl
1143
+ } = this.context;
1282
1144
 
1283
- if (column.template === 'gantt') {
1145
+ if (column.template && column.template.type === 'gantt') {
1284
1146
  return this.getGanttTitle(column);
1285
1147
  }
1286
1148
 
1287
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);
1288
1154
  return /*#__PURE__*/_react.default.createElement("div", {
1289
- style: this.getStyle(),
1155
+ ref: this.dom,
1156
+ "data-uniq-id": dataUniqId,
1157
+ style: this.getStyle(attrs.style),
1290
1158
  draggable: false,
1291
- className: "aio-table-title"
1159
+ className: 'aio-table-title' + (attrs.className ? ' ' + attrs.className : '') + (isLast ? ' last-child' : '') + (rtl ? ' rtl' : ' ltr')
1292
1160
  }, /*#__PURE__*/_react.default.createElement(AIOTableFilter, {
1293
- column: column
1161
+ column: column,
1162
+ dataUniqId: dataUniqId
1294
1163
  }), /*#__PURE__*/_react.default.createElement("div", {
1295
1164
  className: "aio-table-title-text",
1296
1165
  style: {
@@ -1298,8 +1167,8 @@ class AIOTableTitle extends _react.Component {
1298
1167
  cursor: column.movable === false ? undefined : 'move'
1299
1168
  },
1300
1169
  draggable: column.movable !== false,
1301
- onDragStart: () => onDragStart(column._index),
1302
- onDragOver: e => onDragOver(e, column._index),
1170
+ onDragStart: () => onDragStart(column.realIndex),
1171
+ onDragOver: e => onDragOver(e, column.realIndex),
1303
1172
  onDrop: () => onDrop(column)
1304
1173
  }, title), column.width !== 'auto' && /*#__PURE__*/_react.default.createElement("div", {
1305
1174
  className: "aio-table-resize",
@@ -1317,11 +1186,14 @@ class AIOTableTitle extends _react.Component {
1317
1186
  _defineProperty(AIOTableTitle, "contextType", AioTableContext);
1318
1187
 
1319
1188
  class AIOTableGroup extends _react.Component {
1320
- getStyle(columns) {
1189
+ getStyle() {
1321
1190
  let {
1322
1191
  rowHeight,
1323
1192
  fn
1324
1193
  } = this.context;
1194
+ let {
1195
+ columns
1196
+ } = this.props;
1325
1197
  return { ...fn.getFullCellStyle(columns),
1326
1198
  height: rowHeight
1327
1199
  };
@@ -1363,12 +1235,11 @@ class AIOTableGroup extends _react.Component {
1363
1235
  } = this.context;
1364
1236
  let {
1365
1237
  row,
1366
- tableIndex,
1367
- columns
1238
+ tableIndex
1368
1239
  } = this.props;
1369
1240
  return /*#__PURE__*/_react.default.createElement("div", {
1370
1241
  className: "aio-table-group",
1371
- style: this.getStyle(columns)
1242
+ style: this.getStyle()
1372
1243
  }, tableIndex !== 1 && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
1373
1244
  style: {
1374
1245
  width: indent * row._level,
@@ -1404,15 +1275,12 @@ class AIOTableCell extends _react.Component {
1404
1275
 
1405
1276
  getStyle(column, row) {
1406
1277
  var {
1407
- padding = '36px',
1408
1278
  template,
1409
1279
  minWidth = '30px'
1410
1280
  } = column;
1411
1281
  var {
1412
1282
  rowHeight,
1413
- getCellStyle = () => {
1414
- return {};
1415
- }
1283
+ getCellAttrs
1416
1284
  } = this.context;
1417
1285
  var style = {
1418
1286
  height: rowHeight,
@@ -1420,21 +1288,25 @@ class AIOTableCell extends _react.Component {
1420
1288
  minWidth
1421
1289
  };
1422
1290
 
1423
- if (column.template === 'gantt') {
1424
- style.padding = `0 ${padding}`;
1291
+ if (column.template && column.template.type === 'gantt') {
1292
+ style.padding = 0;
1425
1293
  }
1426
1294
 
1427
- let cellStyle = getCellStyle(row, column);
1295
+ let attrs = getCellAttrs(row, column);
1428
1296
  return { ...style,
1429
- ...cellStyle
1297
+ ...attrs.style
1430
1298
  };
1431
1299
  }
1432
1300
 
1433
1301
  getClassName(row, column) {
1302
+ let {
1303
+ getCellAttrs
1304
+ } = this.context;
1434
1305
  var className = 'aio-table-cell';
1435
1306
  let {
1436
1307
  striped
1437
1308
  } = this.props;
1309
+ let attrs = getCellAttrs(row, column);
1438
1310
 
1439
1311
  if (striped) {
1440
1312
  className += ' striped';
@@ -1448,8 +1320,8 @@ class AIOTableCell extends _react.Component {
1448
1320
  className += ' aio-table-cell-gantt';
1449
1321
  }
1450
1322
 
1451
- if (column.className) {
1452
- className += ' ' + column.className;
1323
+ if (attrs.className) {
1324
+ className += ' ' + attrs.className;
1453
1325
  }
1454
1326
 
1455
1327
  if (column.inlineEdit) {
@@ -1482,9 +1354,7 @@ class AIOTableCell extends _react.Component {
1482
1354
  } = this.context;
1483
1355
  let icon;
1484
1356
 
1485
- if (!row._childsLength) {
1486
- icon = '';
1487
- } else if (row._opened) {
1357
+ if (row._opened) {
1488
1358
  icon = aioTableGetSvg('chevronDown');
1489
1359
  } else {
1490
1360
  icon = aioTableGetSvg('chevronRight', {
@@ -1494,55 +1364,124 @@ class AIOTableCell extends _react.Component {
1494
1364
 
1495
1365
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
1496
1366
  className: "aio-table-toggle",
1497
- onClick: () => fn.toggleRow(row)
1367
+ onClick: () => fn.toggleRow(row),
1368
+ style: {
1369
+ opacity: row._childsLength ? 1 : 0
1370
+ }
1498
1371
  }, icon), /*#__PURE__*/_react.default.createElement("div", {
1499
1372
  className: "aio-table-cell-gap"
1500
1373
  }));
1501
1374
  }
1502
1375
 
1503
- getContent(row, column, value) {
1504
- var {
1505
- focused,
1506
- fn
1507
- } = this.context;
1508
- let {
1509
- inlineEdit
1510
- } = this.props;
1511
- var content = '';
1512
- let template = typeof column.template === 'function' ? column.template(row, column) : column.template;
1376
+ splitNumber(num) {
1377
+ if (!num) {
1378
+ return num;
1379
+ }
1513
1380
 
1514
- if (template && template.type === 'slider') {
1515
- content = fn.getSliderCell(template);
1516
- } else if (template && template.type === 'options') {
1517
- content = fn.getOptionsCell(template);
1518
- } else if (template && template.type === 'gantt') {
1519
- content = fn.getGanttCell(row, template);
1520
- } else if (template && inlineEdit) {
1521
- content = focused ? this.getInput(row, column) : template;
1522
- } else if (template) {
1523
- content = template;
1524
- } else if (inlineEdit) {
1525
- content = this.getInput(row, column);
1526
- } else {
1527
- content = value;
1381
+ let str = num.toString();
1382
+ let dotIndex = str.indexOf('.');
1383
+
1384
+ if (dotIndex !== -1) {
1385
+ str = str.slice(0, dotIndex);
1528
1386
  }
1529
1387
 
1530
- if (column.subText) {
1531
- let subText;
1388
+ let res = '';
1389
+ let index = 0;
1532
1390
 
1533
- try {
1534
- subText = column.subText(row);
1535
- } catch {
1536
- subText = '';
1537
- }
1391
+ for (let i = str.length - 1; i >= 0; i--) {
1392
+ res = str[i] + res;
1538
1393
 
1539
- return /*#__PURE__*/_react.default.createElement("div", {
1540
- className: "aio-table-cell-has-subtext"
1541
- }, /*#__PURE__*/_react.default.createElement("div", {
1394
+ if (index === 2) {
1395
+ index = 0;
1396
+
1397
+ if (i > 0) {
1398
+ res = ',' + res;
1399
+ }
1400
+ } else {
1401
+ index++;
1402
+ }
1403
+ }
1404
+
1405
+ return res;
1406
+ }
1407
+
1408
+ getContentByTemplate(row, column, value) {
1409
+ let {
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", {
1542
1477
  className: "aio-table-cell-uptext"
1543
1478
  }, content), /*#__PURE__*/_react.default.createElement("div", {
1544
1479
  className: "aio-table-cell-subtext"
1545
- }, subText));
1480
+ }, subText), /*#__PURE__*/_react.default.createElement("div", {
1481
+ style: {
1482
+ flex: 1
1483
+ }
1484
+ }));
1546
1485
  }
1547
1486
 
1548
1487
  return content;
@@ -1555,7 +1494,7 @@ class AIOTableCell extends _react.Component {
1555
1494
  inlineEdit
1556
1495
  } = this.props;
1557
1496
  let {
1558
- setCellValue
1497
+ fn
1559
1498
  } = this.context;
1560
1499
  let res;
1561
1500
  this.setState({
@@ -1564,8 +1503,8 @@ class AIOTableCell extends _react.Component {
1564
1503
 
1565
1504
  if (inlineEdit.onChange) {
1566
1505
  res = await inlineEdit.onChange(row, value);
1567
- } else {
1568
- 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));
1569
1508
  }
1570
1509
 
1571
1510
  this.setState({
@@ -1576,7 +1515,7 @@ class AIOTableCell extends _react.Component {
1576
1515
 
1577
1516
  getInput(row, column) {
1578
1517
  let {
1579
- getCellValue
1518
+ fn
1580
1519
  } = this.context;
1581
1520
  let {
1582
1521
  attrs,
@@ -1593,7 +1532,7 @@ class AIOTableCell extends _react.Component {
1593
1532
  } = this.state;
1594
1533
 
1595
1534
  if (getValue) {
1596
- value = getCellValue(row, getValue, column.field);
1535
+ value = fn.getCellValue(row, getValue);
1597
1536
  }
1598
1537
 
1599
1538
  if (disabled(row)) {
@@ -1616,7 +1555,7 @@ class AIOTableCell extends _react.Component {
1616
1555
  className: 'aio-table-input-container'
1617
1556
  }, /*#__PURE__*/_react.default.createElement("input", _extends({}, props, {
1618
1557
  style: {
1619
- textAlign: column.justify ? 'center' : undefined
1558
+ textAlign: column.justify || type === 'number' ? 'center' : undefined
1620
1559
  },
1621
1560
  onChange: e => this.setState({
1622
1561
  value: e.target.value
@@ -1630,10 +1569,14 @@ class AIOTableCell extends _react.Component {
1630
1569
  return;
1631
1570
  }
1632
1571
 
1633
- let newValue = type === 'number' ? parseFloat(value) : value;
1572
+ let newValue = value;
1634
1573
 
1635
- if (isNaN(newValue)) {
1636
- newValue = 0;
1574
+ if (type === 'number') {
1575
+ newValue = parseFloat(newValue);
1576
+
1577
+ if (isNaN(newValue)) {
1578
+ newValue = 0;
1579
+ }
1637
1580
  }
1638
1581
 
1639
1582
  let res = await this.changeCell(newValue);
@@ -1749,10 +1692,12 @@ class AIOTableCell extends _react.Component {
1749
1692
  }
1750
1693
 
1751
1694
  getProps(row, column, content) {
1752
- 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;
1753
1697
  return {
1754
1698
  ref: this.dom,
1755
1699
  title,
1700
+ ...attrs,
1756
1701
  style: this.getStyle(column, row),
1757
1702
  className: this.getClassName(row, column)
1758
1703
  };
@@ -1785,6 +1730,11 @@ class AIOTableCell extends _react.Component {
1785
1730
  loading
1786
1731
  } = this.state;
1787
1732
  let content = this.getContent(row, column, value);
1733
+
1734
+ if (column.affix) {
1735
+ content = content + ' ' + column.affix;
1736
+ }
1737
+
1788
1738
  let cell;
1789
1739
 
1790
1740
  if (loading) {
@@ -1833,31 +1783,47 @@ class AIOTableCell extends _react.Component {
1833
1783
  _defineProperty(AIOTableCell, "contextType", AioTableContext);
1834
1784
 
1835
1785
  class AIOTableFilter extends _react.Component {
1836
- change(obj) {
1786
+ constructor(...args) {
1787
+ super(...args);
1788
+
1789
+ _defineProperty(this, "dom", /*#__PURE__*/(0, _react.createRef)());
1790
+ }
1791
+
1792
+ async change(obj) {
1837
1793
  let {
1838
- onChangeFilter,
1839
- filterDictionary,
1840
- SetState
1794
+ SetState,
1795
+ columns
1841
1796
  } = this.context;
1842
1797
  let {
1843
1798
  column
1844
1799
  } = this.props;
1845
- filterDictionary[column._index] = { ...filterDictionary[column._index],
1846
- ...obj
1800
+ column = { ...column,
1801
+ filter: { ...column.filter,
1802
+ ...obj
1803
+ }
1847
1804
  };
1805
+ let approve = true;
1848
1806
 
1849
- if (onChangeFilter) {
1850
- 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
+ });
1851
1816
  }
1852
1817
 
1853
- SetState({
1854
- filterDictionary
1855
- });
1818
+ if (approve !== false) {
1819
+ SetState({
1820
+ columns: columns.map(o => o.realIndex === column.realIndex ? column : o)
1821
+ });
1822
+ }
1856
1823
  }
1857
1824
 
1858
1825
  render() {
1859
1826
  var {
1860
- filterDictionary,
1861
1827
  rtl,
1862
1828
  translate
1863
1829
  } = this.context;
@@ -1869,35 +1835,40 @@ class AIOTableFilter extends _react.Component {
1869
1835
  return null;
1870
1836
  }
1871
1837
 
1872
- if (!filterDictionary[column._index]) {
1873
- return null;
1874
- }
1875
-
1876
1838
  let {
1877
- items,
1878
- booleanType
1879
- } = filterDictionary[column._index];
1880
- let {
1881
- type
1839
+ items = [],
1840
+ booleanType = 'or',
1841
+ type = 'text'
1882
1842
  } = column.filter;
1883
1843
  let icon = items.length ? aioTableGetSvg('filterActive', {
1884
1844
  className: 'has-filter'
1885
1845
  }) : aioTableGetSvg('filter');
1886
1846
  return /*#__PURE__*/_react.default.createElement("div", {
1887
- 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
+ }
1888
1857
  }, /*#__PURE__*/_react.default.createElement(_aioButton.default, {
1889
1858
  type: "button",
1890
1859
  rtl: rtl,
1891
1860
  caret: false,
1892
1861
  openRelatedTo: ".aio-table",
1893
1862
  text: icon,
1894
- popOver: () => /*#__PURE__*/_react.default.createElement(AIOTableFilterPopup, {
1895
- translate,
1896
- type,
1897
- items,
1898
- booleanType,
1899
- onChange: obj => this.change(obj)
1900
- })
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
+ }
1901
1872
  }));
1902
1873
  }
1903
1874
 
@@ -1993,7 +1964,7 @@ class AIOTableFilterItem extends _react.Component {
1993
1964
  getOptions(type, translate) {
1994
1965
  let options = [];
1995
1966
 
1996
- if (type !== 'number') {
1967
+ if (type !== 'number' && type !== 'date') {
1997
1968
  options.push( /*#__PURE__*/_react.default.createElement("option", {
1998
1969
  key: "contain",
1999
1970
  value: "contain"
@@ -2074,7 +2045,8 @@ class AIOTableFilterItem extends _react.Component {
2074
2045
  function ATFN({
2075
2046
  getProps,
2076
2047
  getState,
2077
- setState
2048
+ setState,
2049
+ getContext
2078
2050
  }) {
2079
2051
  let $$ = {
2080
2052
  fixPersianAndArabicNumbers(str) {
@@ -2104,9 +2076,9 @@ function ATFN({
2104
2076
  for (let j = 0; j < columns.length; j++) {
2105
2077
  let {
2106
2078
  title,
2107
- _index
2079
+ realIndex
2108
2080
  } = columns[j];
2109
- let res = row._values[_index];
2081
+ let res = row._values[realIndex];
2110
2082
  obj[title] = res !== undefined ? $$.fixPersianAndArabicNumbers(res) : "";
2111
2083
  }
2112
2084
 
@@ -2168,13 +2140,14 @@ function ATFN({
2168
2140
  document.body.removeChild(link);
2169
2141
  },
2170
2142
 
2171
- getSliderCell({
2172
- colors = ['#eee', 'dodgerblue'],
2173
- start = 0,
2174
- end = 100,
2175
- value,
2176
- editValue = value => value
2177
- }) {
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;
2178
2151
  let {
2179
2152
  rowHeight,
2180
2153
  rtl
@@ -2234,7 +2207,8 @@ function ATFN({
2234
2207
  },
2235
2208
 
2236
2209
  getOptionsCell({
2237
- options = []
2210
+ options,
2211
+ row
2238
2212
  }) {
2239
2213
  return /*#__PURE__*/_react.default.createElement(_aioButton.default, {
2240
2214
  type: "select",
@@ -2248,12 +2222,8 @@ function ATFN({
2248
2222
  }) => {
2249
2223
  return {
2250
2224
  text,
2251
- before: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, icon, /*#__PURE__*/_react.default.createElement("div", {
2252
- style: {
2253
- width: 6
2254
- }
2255
- })),
2256
- onClick
2225
+ before: icon,
2226
+ onClick: () => onClick(row)
2257
2227
  };
2258
2228
  })
2259
2229
  });
@@ -2271,24 +2241,9 @@ function ATFN({
2271
2241
  getProgress = () => false,
2272
2242
  getText = () => false,
2273
2243
  getStart,
2274
- getEnd
2244
+ getEnd,
2245
+ padding = 36
2275
2246
  } = template;
2276
-
2277
- if (typeof getStart !== 'function') {
2278
- console.error('aio table => gantt column => column getStart property is not a function');
2279
- return '';
2280
- }
2281
-
2282
- if (typeof getEnd !== 'function') {
2283
- console.error('aio table => gantt column => column getEnd property is not a function');
2284
- return '';
2285
- }
2286
-
2287
- if (typeof getKeys !== 'function') {
2288
- console.error('aio table => gantt column => column getKeys property is not a function');
2289
- return '';
2290
- }
2291
-
2292
2247
  let keys = getKeys();
2293
2248
 
2294
2249
  if (!Array.isArray(keys)) {
@@ -2296,15 +2251,20 @@ function ATFN({
2296
2251
  return '';
2297
2252
  }
2298
2253
 
2299
- let color = getColor(row);
2300
- let backgroundColor = getBackgroundColor(row);
2301
- let progress = getProgress(row);
2302
- let text = getText(row);
2303
- let startIndex = keys.indexOf(getStart(row));
2304
- let endIndex = keys.indexOf(getEnd(row));
2305
- 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%)`;
2306
2261
  let flags = getFlags();
2307
2262
  return /*#__PURE__*/_react.default.createElement(_rRangeSlider.default, {
2263
+ attrs: {
2264
+ style: {
2265
+ padding: `0 ${+padding}px`
2266
+ }
2267
+ },
2308
2268
  start: 0,
2309
2269
  editValue: value => keys[value],
2310
2270
  end: keys.length - 1,
@@ -2355,25 +2315,41 @@ function ATFN({
2355
2315
  },
2356
2316
 
2357
2317
  handleOutsideClick() {
2358
- (0, _jquery.default)(window).bind('click', e => {
2359
- var {
2360
- focused
2361
- } = getState();
2318
+ (0, _jquery.default)(window).unbind('click', $$.outSideClick);
2319
+ (0, _jquery.default)(window).bind('click', $$.outSideClick);
2320
+ },
2362
2321
 
2363
- if (focused === false) {
2364
- return;
2365
- }
2322
+ outSideClick(e) {
2323
+ let {
2324
+ focused
2325
+ } = getState();
2366
2326
 
2367
- var target = (0, _jquery.default)(e.target);
2327
+ if (focused === false) {
2328
+ return;
2329
+ }
2368
2330
 
2369
- if (target.parents('.aio-table-cell').length !== 0 || target.hasClass('aio-table-cell')) {
2370
- return;
2371
- }
2331
+ let target = (0, _jquery.default)(e.target);
2372
2332
 
2373
- setState({
2374
- focused: false
2375
- });
2376
- });
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');
2377
2353
  },
2378
2354
 
2379
2355
  getCardRowCount() {
@@ -2471,25 +2447,6 @@ function ATFN({
2471
2447
  $$['scroll' + index] = false;
2472
2448
  },
2473
2449
 
2474
- getGroupDictionaty() {
2475
- let {
2476
- id
2477
- } = getProps();
2478
-
2479
- if (id === undefined) {
2480
- return {};
2481
- }
2482
-
2483
- let groupDictionary = localStorage.getItem('aio table group' + id);
2484
-
2485
- if (groupDictionary === null || groupDictionary === undefined) {
2486
- localStorage.setItem('aio table group' + id, '{}');
2487
- return {};
2488
- } else {
2489
- return JSON.parse(groupDictionary);
2490
- }
2491
- },
2492
-
2493
2450
  getOpenDictionary() {
2494
2451
  let {
2495
2452
  id
@@ -2524,319 +2481,423 @@ function ATFN({
2524
2481
  return parseInt(list.map(o => o.length === 1 ? '0' + o : o).join(''));
2525
2482
  },
2526
2483
 
2527
- getSorts(toolbar) {
2484
+ setCellValue: (row, getValue, value) => {
2485
+ //row is used in eval
2528
2486
  let {
2529
- onChangeSort
2487
+ model
2530
2488
  } = getProps();
2531
- let {
2532
- sorts,
2533
- columns = [],
2534
- getCellValue
2535
- } = getState();
2536
- let sortTitles = sorts.map(o => o.title);
2489
+ let evalText;
2537
2490
 
2538
- for (let i = 0; i < columns.length; i++) {
2539
- if (!columns[i].sort) {
2540
- 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);
2541
2504
  }
2542
2505
 
2543
- if (sortTitles.indexOf(columns[i].title) !== -1) {
2544
- continue;
2506
+ if (typeof getValue === 'string') {
2507
+ let result;
2508
+ eval('result = row.' + getValue);
2509
+ return result;
2545
2510
  }
2546
2511
 
2547
- columns[i]._addedToSorts = true;
2548
- let column = columns[i];
2512
+ return;
2513
+ } catch {
2514
+ return;
2515
+ }
2516
+ },
2549
2517
 
2550
- if (column.sort === true) {
2551
- column.sort = {};
2552
- }
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;
2553
2530
 
2531
+ if (column.sort.onChange) {
2554
2532
  let {
2555
- sort
2556
- } = columns[i];
2557
- let a = sort.title || column.title || '';
2558
- let title = typeof a === 'function' ? a() : a;
2559
- let getValue = sort.getValue || column.getValue;
2560
- let field = sort.field || column.field;
2561
- let {
2562
- toggle = true,
2563
- dir = 'inc',
2564
2533
  active = true,
2565
- type
2566
- } = sort;
2567
- sorts.push({
2568
- title,
2569
- dir,
2534
+ dir = 'inc'
2535
+ } = column.sort;
2536
+ approve = await column.sort.onChange({
2570
2537
  active,
2571
- toggle,
2572
- getValue,
2573
- type,
2574
- field
2538
+ dir
2575
2539
  });
2576
2540
  }
2577
2541
 
2578
- let Sorts = sorts.map(o => {
2579
- return { ...o,
2580
- onChangeDir: () => {
2581
- o.dir = o.dir === 'dec' ? 'inc' : 'dec';
2582
- setState({
2583
- sorts
2584
- });
2542
+ if (approve !== false) {
2543
+ setState({
2544
+ columns: newColumns
2545
+ });
2546
+ }
2547
+ },
2585
2548
 
2586
- if (onChangeSort) {
2587
- onChangeSort(Sorts.filter(o => o.active !== false));
2588
- }
2589
- },
2590
- onChangeActive: () => {
2591
- o.active = o.active === undefined ? true : o.active;
2592
- o.active = !o.active;
2593
- setState({
2594
- sorts
2595
- });
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;
2596
2568
 
2597
- if (onChangeSort) {
2598
- onChangeSort(Sorts.filter(o => o.active !== false));
2599
- }
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;
2600
2581
  }
2582
+
2583
+ return $$.getDateNumber(value);
2601
2584
  };
2602
- });
2603
- let result = [];
2585
+ }
2604
2586
 
2605
- for (let i = 0; i < Sorts.length; i++) {
2606
- let sort = Sorts[i];
2607
- let {
2608
- getValue,
2609
- dir = 'inc',
2610
- title,
2611
- active = true,
2612
- toggle = true,
2613
- type,
2614
- onChangeDir,
2615
- onChangeActive,
2616
- field
2617
- } = sort;
2587
+ sorts.push({
2588
+ title,
2589
+ dir,
2590
+ active,
2591
+ toggle,
2592
+ getValue,
2593
+ type,
2594
+ onChange
2595
+ });
2618
2596
 
2619
- if (!title) {
2620
- console.error('aio table => missing sort title property');
2621
- continue;
2622
- }
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
+ },
2623
2621
 
2624
- if (active === true) {
2625
- if (type === 'date') {
2626
- let newGetValue = row => {
2627
- 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
+ };
2628
2640
 
2629
- if (typeof value !== 'string') {
2630
- return 0;
2641
+ if (column.storageKey) {
2642
+ column = { ...column,
2643
+ _storageObj: { ...column._storageObj,
2644
+ show: column.show
2631
2645
  }
2632
-
2633
- return $$.getDateNumber(value);
2634
2646
  };
2635
-
2636
- result.push({
2637
- getValue: row => newGetValue(row),
2638
- dir
2639
- });
2640
- } else {
2641
- result.push({
2642
- getValue,
2643
- dir
2644
- });
2647
+ localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
2645
2648
  }
2646
- }
2647
2649
 
2648
- if (toggle) {
2649
- toolbar.show = true;
2650
- toolbar.sort.push({
2651
- text: title,
2652
- checked: active === true,
2653
- after: /*#__PURE__*/_react.default.createElement("div", {
2654
- style: {
2655
- width: '30px',
2656
- display: 'flex',
2657
- justifyContent: 'flex-end'
2658
- }
2659
- }, aioTableGetSvg(dir === 'dec' ? 'arrowDown' : 'arrowUp', {
2660
- onClick: e => {
2661
- e.stopPropagation();
2662
- onChangeDir();
2663
- }
2664
- })),
2665
- onClick: () => onChangeActive()
2650
+ setState({
2651
+ columns: columns.map((o, i) => i === column.realIndex ? column : o)
2666
2652
  });
2667
2653
  }
2668
- }
2669
-
2670
- return result;
2654
+ });
2671
2655
  },
2672
2656
 
2673
- getGroups(toolbar) {
2674
- var {
2675
- id
2676
- } = getProps();
2677
- var {
2678
- groups,
2679
- groupDictionary
2680
- } = getState();
2681
- let result = [];
2682
-
2683
- for (let i = 0; i < groups.length; i++) {
2684
- let group = groups[i];
2685
- let {
2686
- title,
2687
- active = true,
2688
- toggle = true
2689
- } = group;
2690
-
2691
- if (!title) {
2692
- console.error('aio table => missing group title property');
2693
- continue;
2694
- }
2695
-
2696
- groupDictionary[title] = groupDictionary[title] === undefined ? active : groupDictionary[title];
2697
-
2698
- if (groupDictionary[title]) {
2699
- result.push(group);
2700
- }
2701
-
2702
- if (toggle) {
2703
- toolbar.show = true;
2704
- toolbar.groupBy.push({
2705
- text: title,
2706
- checked: groupDictionary[title],
2707
- onClick: () => {
2708
- 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);
2709
2666
 
2710
- if (id) {
2711
- localStorage.setItem('aio table group' + id, JSON.stringify(groupDictionary));
2712
- }
2667
+ if (!column.toggleFreeze) {
2668
+ return;
2669
+ }
2713
2670
 
2714
- setState({
2715
- groupDictionary
2716
- });
2717
- }
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)
2718
2684
  });
2719
2685
  }
2720
- }
2721
-
2722
- return result;
2686
+ });
2723
2687
  },
2724
2688
 
2725
- setColumnByStorage(column) {
2726
- if (column.storageKey && !column._readStorage) {
2689
+ updateColumnByStorage(column) {
2690
+ let {
2691
+ storageKey,
2692
+ _readStorage
2693
+ } = column;
2694
+
2695
+ if (storageKey && !_readStorage) {
2727
2696
  column._readStorage = true;
2728
2697
  let storageStr = localStorage.getItem('aio-table-column-storage-' + column.storageKey);
2698
+ let storageObj;
2729
2699
 
2730
2700
  if (!storageStr || storageStr === null) {
2731
- column._storageObj = {};
2732
- localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
2701
+ storageObj = {};
2702
+ localStorage.setItem('aio-table-column-storage-' + column.storageKey, '{}');
2733
2703
  } else {
2734
- column._storageObj = JSON.parse(storageStr);
2704
+ storageObj = JSON.parse(storageStr);
2735
2705
  }
2736
2706
 
2737
- if (column._storageObj.show !== undefined) {
2738
- column.show = column._storageObj.show;
2739
- } else {
2740
- column.show = column.show === undefined ? true : column.show;
2707
+ if (storageObj.show !== undefined) {
2708
+ column.show = storageObj.show;
2741
2709
  }
2742
2710
 
2743
- if (column._storageObj.width !== undefined) {
2744
- column.width = column._storageObj.width;
2745
- } else {
2746
- column.width = column.width || 'auto';
2711
+ if (storageObj.width !== undefined) {
2712
+ column.width = storageObj.width;
2747
2713
  }
2748
- } else {
2749
- column.show = column.show === undefined ? true : column.show;
2750
- column.width = column.width || 'auto';
2714
+
2715
+ column._storageObj = storageObj;
2751
2716
  }
2752
2717
  },
2753
2718
 
2754
- getFreezes(index, columnDetails, toolbar) {
2719
+ getDetails() {
2755
2720
  let {
2756
- columns
2721
+ columns,
2722
+ groups
2757
2723
  } = getState();
2758
- 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;
2759
2737
 
2760
- if (column.freeze) {
2761
- columnDetails.freeze.active = true;
2762
- columnDetails.freeze.freezeColumns.push(column);
2763
- } else {
2764
- columnDetails.freeze.unFreezeColumns.push(column);
2765
- }
2766
-
2767
- if (column.toggleFreeze) {
2768
- toolbar.show = true;
2769
- toolbar.freeze.push({
2770
- text: column.title,
2771
- checked: column.freeze === true,
2772
- onClick: () => {
2773
- let state = columns[index].freeze === true ? true : false;
2774
- let column = { ...columns[index],
2775
- freeze: !state
2776
- };
2777
- setState({
2778
- columns: columns.map((c, i) => {
2779
- if (i === index) {
2780
- return column;
2781
- }
2782
-
2783
- return c;
2784
- })
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
2785
2810
  });
2786
2811
  }
2787
- });
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
+ }
2788
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
+ };
2789
2846
  },
2790
2847
 
2791
- getToggleShows(index, toolbar) {
2792
- let {
2793
- columns
2848
+ getGroups(groupOptions) {
2849
+ var {
2850
+ groups
2794
2851
  } = getState();
2795
- let column = columns[index];
2796
- let {
2797
- show,
2798
- storageKey
2799
- } = column;
2800
- let title = typeof column.title === 'function' ? column.title() : column.title;
2801
- toolbar.show = true;
2802
- toolbar.toggle.push({
2803
- text: title,
2804
- checked: show !== false,
2805
- onClick: () => {
2806
- //change columns imutable(prevent change columns directly)
2807
- let {
2808
- columns
2809
- } = getState();
2810
- let column = columns[index];
2811
- let newColumn;
2812
2852
 
2813
- if (storageKey) {
2814
- let newShow = !column._storageObj.show;
2815
- let newStorageObj = { ...column._storageObj,
2816
- show: newShow
2817
- };
2818
- newColumn = { ...column,
2819
- _storageObj: newStorageObj,
2820
- show: newShow
2821
- };
2822
- 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));
2823
2870
  } else {
2824
- newColumn = { ...column,
2825
- show: !column.show
2826
- };
2871
+ storageActive = JSON.parse(storageActive);
2827
2872
  }
2828
2873
 
2829
- setState({
2830
- columns: columns.map((c, i) => {
2831
- if (i === index) {
2832
- 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));
2833
2892
  }
2834
2893
 
2835
- return c;
2836
- })
2894
+ setState({
2895
+ groups
2896
+ });
2897
+ }
2837
2898
  });
2838
2899
  }
2839
- });
2900
+ }
2840
2901
  },
2841
2902
 
2842
2903
  isContain(text, subtext) {
@@ -3001,13 +3062,12 @@ function ATFN({
3001
3062
 
3002
3063
  getFilterResult(column, value) {
3003
3064
  let {
3004
- filterDictionary
3005
- } = getState();
3006
- let filters = filterDictionary[column._index].items;
3065
+ items = [],
3066
+ booleanType = 'or'
3067
+ } = column.filter;
3007
3068
 
3008
- if (filters.length) {
3009
- let booleanType = filterDictionary[column._index].booleanType;
3010
- return $$['getFilterResult_' + booleanType](filters, value);
3069
+ if (items.length) {
3070
+ return $$['getFilterResult_' + booleanType](items, value);
3011
3071
  }
3012
3072
 
3013
3073
  return true;
@@ -3076,31 +3136,6 @@ function ATFN({
3076
3136
  }));
3077
3137
  },
3078
3138
 
3079
- getBodyStyle(Toolbar) {
3080
- let {
3081
- paging
3082
- } = getState();
3083
- let {
3084
- padding
3085
- } = getProps();
3086
- var def = padding,
3087
- top = 0;
3088
-
3089
- if (paging) {
3090
- def += 36;
3091
- }
3092
-
3093
- if (Toolbar !== null) {
3094
- def += 36;
3095
- top += 36;
3096
- }
3097
-
3098
- return {
3099
- height: `calc(100% - ${def}px)`,
3100
- top
3101
- };
3102
- },
3103
-
3104
3139
  toggleRow(row) {
3105
3140
  var {
3106
3141
  openDictionary
@@ -3124,21 +3159,15 @@ function ATFN({
3124
3159
  });
3125
3160
  },
3126
3161
 
3127
- getRow(row, columnDetails) {
3162
+ getRow(row) {
3128
3163
  let {
3129
- visibleColumns: columns,
3130
- freeze
3131
- } = columnDetails;
3132
- var {
3133
- onChangeFilter,
3134
- search
3135
- } = getProps();
3136
- let {
3137
- filterDictionary,
3138
- searchText,
3139
- getCellValue
3164
+ searchText
3140
3165
  } = getState();
3166
+ let {
3167
+ columns
3168
+ } = getContext().details;
3141
3169
  row._values = {};
3170
+ let searchShow;
3142
3171
  let show = true,
3143
3172
  lastColumn,
3144
3173
  isThereAutoColumn = false,
@@ -3147,35 +3176,33 @@ function ATFN({
3147
3176
  unFreezeCells = [];
3148
3177
 
3149
3178
  for (let i = 0; i < columns.length; i++) {
3150
- let column = columns[i],
3151
- value = getCellValue(row, column.getValue, column.field);
3152
- row._values[column._index] = value;
3153
- filterDictionary[column._index] = filterDictionary[column._index] || {
3154
- items: [],
3155
- booleanType: 'or'
3156
- };
3179
+ let column = columns[i];
3180
+ let value = $$.getCellValue(row, column.getValue);
3181
+ row._values[column.realIndex] = value;
3182
+
3183
+ if (show && column.search && searchText) {
3184
+ if (searchShow === undefined) {
3185
+ searchShow = false;
3186
+ }
3157
3187
 
3158
- if (show && search) {
3159
- show = search(row, searchText);
3188
+ searchShow = searchShow || JSON.stringify(value).toLowerCase().indexOf(searchText.toLowerCase()) !== -1;
3160
3189
  }
3161
3190
 
3162
- if (show && !onChangeFilter) {
3191
+ if (show && column.filter && !column.filter.onChange) {
3163
3192
  show = show && $$.getFilterResult(column, value);
3164
3193
  }
3165
3194
 
3166
3195
  let obj = {
3167
- key: row._index + ',' + column._index,
3196
+ key: row._index + ',' + column.realIndex,
3168
3197
  column,
3169
3198
  value,
3170
3199
  freeze: column.freeze
3171
3200
  };
3172
3201
 
3173
- if (freeze.active) {
3202
+ if ($$.freezeMode) {
3174
3203
  if (column.freeze) {
3175
- column._renderIndex = freezeCells.length;
3176
3204
  freezeCells.push(obj);
3177
3205
  } else {
3178
- column._renderIndex = unFreezeCells.length;
3179
3206
  lastColumn = column;
3180
3207
  unFreezeCells.push(obj);
3181
3208
 
@@ -3184,7 +3211,6 @@ function ATFN({
3184
3211
  }
3185
3212
  }
3186
3213
  } else {
3187
- column._renderIndex = i;
3188
3214
  cells.push(obj);
3189
3215
  lastColumn = column;
3190
3216
 
@@ -3194,7 +3220,7 @@ function ATFN({
3194
3220
  }
3195
3221
  }
3196
3222
 
3197
- row._show = show;
3223
+ row._show = show && searchShow !== false;
3198
3224
 
3199
3225
  if (show) {
3200
3226
  let parents = row._getParents();
@@ -3266,29 +3292,6 @@ function ATFN({
3266
3292
  };
3267
3293
  },
3268
3294
 
3269
- showColumnRelativeGroups(column) {
3270
- var {
3271
- groups
3272
- } = getState();
3273
-
3274
- if (!groups) {
3275
- return true;
3276
- }
3277
-
3278
- if (!groups.length) {
3279
- return true;
3280
- }
3281
-
3282
- if (!column.groupName) {
3283
- return true;
3284
- }
3285
-
3286
- var {
3287
- groupDictionary
3288
- } = getState();
3289
- return groupDictionary[column.groupName] !== true;
3290
- },
3291
-
3292
3295
  getClient(e) {
3293
3296
  return getState().touch ? [e.changedTouches[0].clientX, e.changedTouches[0].clientY] : [e.clientX, e.clientY];
3294
3297
  },
@@ -3347,11 +3350,11 @@ function ATFN({
3347
3350
  let childs = [];
3348
3351
 
3349
3352
  if (getRowChilds) {
3350
- childs = getRowChilds(row) || [];
3353
+ childs = $$.getCellValue(row, getRowChilds) || [];
3351
3354
  row._childsLength = childs.length;
3352
3355
  }
3353
3356
 
3354
- let Row = $$.getRow(row, $$.columnDetails);
3357
+ let Row = $$.getRow(row);
3355
3358
 
3356
3359
  if (row._level === 0) {
3357
3360
  rows.push([]);
@@ -3403,27 +3406,24 @@ function ATFN({
3403
3406
  },
3404
3407
 
3405
3408
  getRowsBySort(rows, sorts) {
3406
- let {
3407
- getCellValue
3408
- } = getState();
3409
-
3410
3409
  if (!sorts.length) {
3411
3410
  return rows;
3412
3411
  }
3413
3412
 
3414
- if (getProps().onChangeSort) {
3415
- return rows;
3416
- }
3417
-
3418
3413
  return rows.sort((a, b) => {
3419
3414
  for (let i = 0; i < sorts.length; i++) {
3420
3415
  let {
3421
3416
  getValue,
3422
3417
  dir,
3423
- field
3418
+ onChange
3424
3419
  } = sorts[i];
3425
- let aValue = getCellValue(a, getValue, field),
3426
- bValue = getCellValue(b, getValue, field);
3420
+
3421
+ if (onChange) {
3422
+ continue;
3423
+ }
3424
+
3425
+ let aValue = $$.getCellValue(a, getValue),
3426
+ bValue = $$.getCellValue(b, getValue);
3427
3427
 
3428
3428
  if (aValue < bValue) {
3429
3429
  return -1 * (dir === 'dec' ? -1 : 1);
@@ -3433,21 +3433,19 @@ function ATFN({
3433
3433
  return 1 * (dir === 'dec' ? -1 : 1);
3434
3434
  }
3435
3435
 
3436
- if (i !== sorts.length - 1) {
3437
- continue;
3436
+ if (i === sorts.length - 1) {
3437
+ return 0;
3438
3438
  }
3439
-
3440
- return 0;
3441
3439
  }
3442
3440
 
3443
3441
  return 0;
3444
3442
  });
3445
3443
  },
3446
3444
 
3447
- getRows(model, columnDetails) {
3445
+ getRows(model, freezeMode) {
3448
3446
  let rows = [];
3449
3447
  $$.realIndex = 0;
3450
- $$.columnDetails = columnDetails;
3448
+ $$.freezeMode = freezeMode;
3451
3449
  $$.getRowsReq(model, rows, 0, [], []);
3452
3450
  let result = [];
3453
3451
 
@@ -3510,8 +3508,7 @@ function ATFN({
3510
3508
  }
3511
3509
 
3512
3510
  var {
3513
- groupsOpen,
3514
- getCellValue
3511
+ groupsOpen
3515
3512
  } = getState();
3516
3513
 
3517
3514
  function msf(obj, _level, parents) {
@@ -3543,7 +3540,7 @@ function ATFN({
3543
3540
  for (let i = 0; i < roots.length; i++) {
3544
3541
  let root = roots[i];
3545
3542
  var obj = newModel;
3546
- 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));
3547
3544
 
3548
3545
  for (let j = 0; j < values.length; j++) {
3549
3546
  let value = values[j];
@@ -3604,6 +3601,7 @@ function ATFN({
3604
3601
  };
3605
3602
  return {
3606
3603
  exportToExcel: $$.exportToExcel,
3604
+ getDetails: $$.getDetails,
3607
3605
  getSliderCell: $$.getSliderCell,
3608
3606
  getOptionsCell: $$.getOptionsCell,
3609
3607
  getGanttCell: $$.getGanttCell,
@@ -3611,23 +3609,17 @@ function ATFN({
3611
3609
  onScroll: $$.onScroll,
3612
3610
  getCardRowCount: $$.getCardRowCount,
3613
3611
  getOpenDictionary: $$.getOpenDictionary,
3614
- getGroupDictionaty: $$.getGroupDictionaty,
3615
- getSorts: $$.getSorts,
3616
3612
  getRowsBySort: $$.getRowsBySort,
3617
3613
  getGroups: $$.getGroups,
3618
3614
  getRootsByGroup: $$.getRootsByGroup,
3619
3615
  setColumnByStorage: $$.setColumnByStorage,
3620
- getFreezes: $$.getFreezes,
3621
- getToggleShows: $$.getToggleShows,
3622
3616
  getFilterResult: $$.getFilterResult,
3623
3617
  getLoading: $$.getLoading,
3624
3618
  cubes2: $$.cubes2,
3625
- getBodyStyle: $$.getBodyStyle,
3626
3619
  getRow: $$.getRow,
3627
3620
  getRowById: $$.getRowById,
3628
3621
  getClient: $$.getClient,
3629
3622
  getStateByToggleAll: $$.getStateByToggleAll,
3630
- showColumnRelativeGroups: $$.showColumnRelativeGroups,
3631
3623
  getRootsByPaging: $$.getRootsByPaging,
3632
3624
  getRowsReq: $$.getRowsReq,
3633
3625
  getRowsNested: $$.getRowsNested,
@@ -3636,7 +3628,10 @@ function ATFN({
3636
3628
  getRowsByRoots: $$.getRowsByRoots,
3637
3629
  toggleRow: $$.toggleRow,
3638
3630
  getFullCellStyle: $$.getFullCellStyle,
3639
- getNoData: $$.getNoData
3631
+ getNoData: $$.getNoData,
3632
+ getSortsFromColumns: $$.getSortsFromColumns,
3633
+ getCellValue: $$.getCellValue,
3634
+ setCellValue: $$.setCellValue
3640
3635
  };
3641
3636
  }
3642
3637