aio-table 7.0.3 → 7.1.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 (2) hide show
  1. package/index.js +74 -57
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -898,10 +898,6 @@ class AIOTableUnit extends _react.Component {
898
898
  }), rows && rows.length === 0 && fn.getNoData(columns), !rows && fn.getLoading());
899
899
  }
900
900
 
901
- getPropValue(row, column, prop) {
902
- return typeof prop === 'function' ? prop(row, column) : prop;
903
- }
904
-
905
901
  render() {
906
902
  var {
907
903
  onScroll,
@@ -912,7 +908,8 @@ class AIOTableUnit extends _react.Component {
912
908
  focused,
913
909
  SetState,
914
910
  striped,
915
- getCellAttrs
911
+ getCellAttrs,
912
+ fn
916
913
  } = this.context;
917
914
  var {
918
915
  rows,
@@ -953,7 +950,7 @@ class AIOTableUnit extends _react.Component {
953
950
  }, j) => {
954
951
  let row = o.row;
955
952
  let cellId = i + '-' + j + '-' + tableIndex;
956
- let inlineEdit = this.getPropValue(row, column, column.inlineEdit);
953
+ let inlineEdit = fn.getValueByField(row, column, column.inlineEdit);
957
954
  let attrs = getCellAttrs(row, column);
958
955
  return /*#__PURE__*/_react.default.createElement(AIOTableCell, {
959
956
  key: cellId,
@@ -1003,8 +1000,8 @@ class AIOTableUnit extends _react.Component {
1003
1000
  column: column,
1004
1001
  row: row,
1005
1002
  inlineEdit: inlineEdit,
1006
- before: this.getPropValue(row, column, column.before),
1007
- after: this.getPropValue(row, column, column.after),
1003
+ before: fn.getValueByField(row, column, column.before),
1004
+ after: fn.getValueByField(row, column, column.after),
1008
1005
  justify: column.justify !== false && !column.treeMode
1009
1006
  });
1010
1007
  });
@@ -1100,7 +1097,8 @@ class AIOTableTitle extends _react.Component {
1100
1097
  var {
1101
1098
  touch,
1102
1099
  columns,
1103
- SetState
1100
+ SetState,
1101
+ fn
1104
1102
  } = this.context;
1105
1103
  var {
1106
1104
  newWidth
@@ -1111,16 +1109,9 @@ class AIOTableTitle extends _react.Component {
1111
1109
  column = { ...column,
1112
1110
  width: newWidth
1113
1111
  };
1114
-
1115
- if (column.storageKey) {
1116
- column = { ...column,
1117
- _storageObj: { ...column._storageObj,
1118
- width: newWidth
1119
- }
1120
- };
1121
- localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
1122
- }
1123
-
1112
+ column = fn.updateStorageByColumn(column, {
1113
+ width: newWidth
1114
+ });
1124
1115
  columns = columns.map((c, i) => i === column.realIndex ? column : c);
1125
1116
  SetState({
1126
1117
  columns
@@ -1490,7 +1481,7 @@ class AIOTableCell extends _react.Component {
1490
1481
  }
1491
1482
 
1492
1483
  if (template.type === 'gantt') {
1493
- return fn.getGanttCell(row, template);
1484
+ return fn.getGanttCell(row, template, column);
1494
1485
  }
1495
1486
 
1496
1487
  return template;
@@ -1498,7 +1489,8 @@ class AIOTableCell extends _react.Component {
1498
1489
 
1499
1490
  getContent(row, column, value) {
1500
1491
  let {
1501
- focused
1492
+ focused,
1493
+ fn
1502
1494
  } = this.context;
1503
1495
  let {
1504
1496
  inlineEdit
@@ -1516,7 +1508,7 @@ class AIOTableCell extends _react.Component {
1516
1508
  let subText;
1517
1509
 
1518
1510
  try {
1519
- subText = column.subText(row);
1511
+ subText = fn.getValueByField(row, column, column.subText);
1520
1512
  } catch {
1521
1513
  subText = '';
1522
1514
  }
@@ -1586,7 +1578,7 @@ class AIOTableCell extends _react.Component {
1586
1578
  } = this.state;
1587
1579
 
1588
1580
  if (getValue) {
1589
- value = fn.getCellValue(row, getValue);
1581
+ value = fn.getValueByField(row, column, getValue);
1590
1582
  }
1591
1583
 
1592
1584
  if (disabled(row)) {
@@ -2318,7 +2310,7 @@ function ATFN({
2318
2310
  }
2319
2311
  },
2320
2312
 
2321
- getGanttCell(row, template) {
2313
+ getGanttCell(row, template, column) {
2322
2314
  let {
2323
2315
  rtl
2324
2316
  } = getProps();
@@ -2340,12 +2332,12 @@ function ATFN({
2340
2332
  return '';
2341
2333
  }
2342
2334
 
2343
- let color = $$.getCellValue(row, getColor);
2344
- let backgroundColor = $$.getCellValue(row, getBackgroundColor);
2345
- let progress = $$.getCellValue(row, getProgress);
2346
- let text = $$.getCellValue(row, getText);
2347
- let startIndex = keys.indexOf($$.getCellValue(row, getStart));
2348
- let endIndex = keys.indexOf($$.getCellValue(row, getEnd));
2335
+ let color = $$.getValueByField(row, column, getColor);
2336
+ let backgroundColor = $$.getValueByField(row, column, getBackgroundColor);
2337
+ let progress = $$.getValueByField(row, column, getProgress);
2338
+ let text = $$.getValueByField(row, column, getText);
2339
+ let startIndex = keys.indexOf($$.getValueByField(row, column, getStart));
2340
+ let endIndex = keys.indexOf($$.getValueByField(row, column, getEnd));
2349
2341
  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%)`;
2350
2342
  let flags = getFlags();
2351
2343
  return /*#__PURE__*/_react.default.createElement(_rRangeSlider.default, {
@@ -2586,19 +2578,26 @@ function ATFN({
2586
2578
  eval(evalText);
2587
2579
  return model;
2588
2580
  },
2589
- getCellValue: (row, getValue) => {
2581
+ getValueByField: (row, column, getValue) => {
2582
+ let props = getProps();
2583
+ let type = typeof getValue;
2584
+
2590
2585
  try {
2591
- if (typeof getValue === 'function') {
2592
- return getValue(row);
2586
+ if (type === 'function') {
2587
+ return getValue(row, column);
2593
2588
  }
2594
2589
 
2595
- if (typeof getValue === 'string') {
2596
- let result;
2597
- eval('result = row.' + getValue);
2598
- return result;
2590
+ if (type === 'string') {
2591
+ if (getValue.indexOf('.') !== -1 && getValue.indexOf('row') !== -1 || getValue.indexOf('column') !== -1 || getValue.indexOf('props') !== -1) {
2592
+ let result;
2593
+ eval('result = ' + getValue);
2594
+ return result;
2595
+ }
2596
+
2597
+ return getValue;
2599
2598
  }
2600
2599
 
2601
- return;
2600
+ return getValue;
2602
2601
  } catch {
2603
2602
  return;
2604
2603
  }
@@ -2614,6 +2613,13 @@ function ATFN({
2614
2613
  column.sort = { ...column.sort,
2615
2614
  ...obj
2616
2615
  };
2616
+
2617
+ if (!column.sort.onChange && column.storageKey) {
2618
+ column = $$.updateStorageByColumn(column, {
2619
+ sort: column.sort
2620
+ });
2621
+ }
2622
+
2617
2623
  let newColumns = columns.map((o, i) => i === colIndex ? column : o);
2618
2624
  let approve = true;
2619
2625
 
@@ -2663,7 +2669,7 @@ function ATFN({
2663
2669
  let {
2664
2670
  getValue = column.getValue
2665
2671
  } = sort;
2666
- let value = $$.getCellValue(row, getValue);
2672
+ let value = $$.getValueByField(row, column, getValue);
2667
2673
 
2668
2674
  if (typeof value !== 'string') {
2669
2675
  return 0;
@@ -2726,16 +2732,9 @@ function ATFN({
2726
2732
  let column = { ...obj.column,
2727
2733
  show: !obj.column.show
2728
2734
  };
2729
-
2730
- if (column.storageKey) {
2731
- column = { ...column,
2732
- _storageObj: { ...column._storageObj,
2733
- show: column.show
2734
- }
2735
- };
2736
- localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
2737
- }
2738
-
2735
+ column = $$.updateStorageByColumn(column, {
2736
+ show: column.show
2737
+ });
2739
2738
  setState({
2740
2739
  columns: columns.map((o, i) => i === column.realIndex ? column : o)
2741
2740
  });
@@ -2801,10 +2800,27 @@ function ATFN({
2801
2800
  column.width = storageObj.width;
2802
2801
  }
2803
2802
 
2803
+ if (storageObj.sort !== undefined) {
2804
+ column.sort = storageObj.sort;
2805
+ }
2806
+
2804
2807
  column._storageObj = storageObj;
2805
2808
  }
2806
2809
  },
2807
2810
 
2811
+ updateStorageByColumn(column, obj) {
2812
+ if (column.storageKey) {
2813
+ column = { ...column,
2814
+ _storageObj: { ...column._storageObj,
2815
+ ...obj
2816
+ }
2817
+ };
2818
+ localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
2819
+ }
2820
+
2821
+ return column;
2822
+ },
2823
+
2808
2824
  getDetails() {
2809
2825
  let {
2810
2826
  columns,
@@ -2955,7 +2971,7 @@ function ATFN({
2955
2971
 
2956
2972
  if (storageActive === null) {
2957
2973
  storageActive = true;
2958
- localStorage.setItem('aio table group' + storageKey, JSON.stringify(storageAtive));
2974
+ localStorage.setItem('aio table group' + storageKey, JSON.stringify(storageActive));
2959
2975
  } else {
2960
2976
  storageActive = JSON.parse(storageActive);
2961
2977
  }
@@ -3266,7 +3282,7 @@ function ATFN({
3266
3282
 
3267
3283
  for (let i = 0; i < columns.length; i++) {
3268
3284
  let column = columns[i];
3269
- let value = $$.getCellValue(row, column.getValue);
3285
+ let value = $$.getValueByField(row, column, column.getValue);
3270
3286
  row._values[column.realIndex] = value;
3271
3287
 
3272
3288
  if (show && column.search && searchText) {
@@ -3439,7 +3455,7 @@ function ATFN({
3439
3455
  let childs = [];
3440
3456
 
3441
3457
  if (getRowChilds) {
3442
- childs = $$.getCellValue(row, getRowChilds) || [];
3458
+ childs = $$.getValueByField(row, undefined, getRowChilds) || [];
3443
3459
  row._childsLength = childs.length;
3444
3460
  }
3445
3461
 
@@ -3511,8 +3527,8 @@ function ATFN({
3511
3527
  continue;
3512
3528
  }
3513
3529
 
3514
- let aValue = $$.getCellValue(a, getValue),
3515
- bValue = $$.getCellValue(b, getValue);
3530
+ let aValue = $$.getValueByField(a, undefined, getValue),
3531
+ bValue = $$.getValueByField(b, undefined, getValue);
3516
3532
 
3517
3533
  if (aValue < bValue) {
3518
3534
  return -1 * (dir === 'dec' ? -1 : 1);
@@ -3629,7 +3645,7 @@ function ATFN({
3629
3645
  for (let i = 0; i < roots.length; i++) {
3630
3646
  let root = roots[i];
3631
3647
  var obj = newModel;
3632
- let values = groups.map(group => $$.getCellValue(root[0].row, group.getValue, group.field));
3648
+ let values = groups.map(group => $$.getValueByField(root[0].row, undefined, group.getValue));
3633
3649
 
3634
3650
  for (let j = 0; j < values.length; j++) {
3635
3651
  let value = values[j];
@@ -3720,8 +3736,9 @@ function ATFN({
3720
3736
  getFullCellStyle: $$.getFullCellStyle,
3721
3737
  getNoData: $$.getNoData,
3722
3738
  getSortsFromColumns: $$.getSortsFromColumns,
3723
- getCellValue: $$.getCellValue,
3724
- setCellValue: $$.setCellValue
3739
+ getValueByField: $$.getValueByField,
3740
+ setCellValue: $$.setCellValue,
3741
+ updateStorageByColumn: $$.updateStorageByColumn
3725
3742
  };
3726
3743
  }
3727
3744
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-table",
3
- "version": "7.0.3",
3
+ "version": "7.1.0",
4
4
  "description": "all in one table. tree mode , simple mode , tree mode, gantt mode , groupby mode, freeze mode.",
5
5
  "main": "index.js",
6
6
  "scripts": {