aio-table 7.0.1 → 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 +79 -59
  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,
@@ -992,7 +989,10 @@ class AIOTableUnit extends _react.Component {
992
989
  SetState({
993
990
  focused: cellId
994
991
  }, 'cellonClick');
995
- setTimeout(() => (0, _jquery.default)('.aio-table-input:focus').select(), 10);
992
+ setTimeout(() => {
993
+ let dom = (0, _jquery.default)(`[data-cell-id = ${cellId}]`).find('.aio-table-input');
994
+ dom.focus().select();
995
+ }, 10);
996
996
  }
997
997
  },
998
998
  striped: this.renderIndex % 2 === 0 && striped,
@@ -1000,8 +1000,8 @@ class AIOTableUnit extends _react.Component {
1000
1000
  column: column,
1001
1001
  row: row,
1002
1002
  inlineEdit: inlineEdit,
1003
- before: this.getPropValue(row, column, column.before),
1004
- after: this.getPropValue(row, column, column.after),
1003
+ before: fn.getValueByField(row, column, column.before),
1004
+ after: fn.getValueByField(row, column, column.after),
1005
1005
  justify: column.justify !== false && !column.treeMode
1006
1006
  });
1007
1007
  });
@@ -1097,7 +1097,8 @@ class AIOTableTitle extends _react.Component {
1097
1097
  var {
1098
1098
  touch,
1099
1099
  columns,
1100
- SetState
1100
+ SetState,
1101
+ fn
1101
1102
  } = this.context;
1102
1103
  var {
1103
1104
  newWidth
@@ -1108,16 +1109,9 @@ class AIOTableTitle extends _react.Component {
1108
1109
  column = { ...column,
1109
1110
  width: newWidth
1110
1111
  };
1111
-
1112
- if (column.storageKey) {
1113
- column = { ...column,
1114
- _storageObj: { ...column._storageObj,
1115
- width: newWidth
1116
- }
1117
- };
1118
- localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
1119
- }
1120
-
1112
+ column = fn.updateStorageByColumn(column, {
1113
+ width: newWidth
1114
+ });
1121
1115
  columns = columns.map((c, i) => i === column.realIndex ? column : c);
1122
1116
  SetState({
1123
1117
  columns
@@ -1458,7 +1452,7 @@ class AIOTableCell extends _react.Component {
1458
1452
  let {
1459
1453
  fn
1460
1454
  } = this.context;
1461
- let template = typeof column.template === 'function' ? column.template(row, column) : column.template;
1455
+ let template = typeof column.template === 'function' ? column.template(row, column, value) : column.template;
1462
1456
 
1463
1457
  if (!template) {
1464
1458
  return value;
@@ -1487,7 +1481,7 @@ class AIOTableCell extends _react.Component {
1487
1481
  }
1488
1482
 
1489
1483
  if (template.type === 'gantt') {
1490
- return fn.getGanttCell(row, template);
1484
+ return fn.getGanttCell(row, template, column);
1491
1485
  }
1492
1486
 
1493
1487
  return template;
@@ -1495,7 +1489,8 @@ class AIOTableCell extends _react.Component {
1495
1489
 
1496
1490
  getContent(row, column, value) {
1497
1491
  let {
1498
- focused
1492
+ focused,
1493
+ fn
1499
1494
  } = this.context;
1500
1495
  let {
1501
1496
  inlineEdit
@@ -1513,7 +1508,7 @@ class AIOTableCell extends _react.Component {
1513
1508
  let subText;
1514
1509
 
1515
1510
  try {
1516
- subText = column.subText(row);
1511
+ subText = fn.getValueByField(row, column, column.subText);
1517
1512
  } catch {
1518
1513
  subText = '';
1519
1514
  }
@@ -1583,7 +1578,7 @@ class AIOTableCell extends _react.Component {
1583
1578
  } = this.state;
1584
1579
 
1585
1580
  if (getValue) {
1586
- value = fn.getCellValue(row, getValue);
1581
+ value = fn.getValueByField(row, column, getValue);
1587
1582
  }
1588
1583
 
1589
1584
  if (disabled(row)) {
@@ -2315,7 +2310,7 @@ function ATFN({
2315
2310
  }
2316
2311
  },
2317
2312
 
2318
- getGanttCell(row, template) {
2313
+ getGanttCell(row, template, column) {
2319
2314
  let {
2320
2315
  rtl
2321
2316
  } = getProps();
@@ -2337,12 +2332,12 @@ function ATFN({
2337
2332
  return '';
2338
2333
  }
2339
2334
 
2340
- let color = $$.getCellValue(row, getColor);
2341
- let backgroundColor = $$.getCellValue(row, getBackgroundColor);
2342
- let progress = $$.getCellValue(row, getProgress);
2343
- let text = $$.getCellValue(row, getText);
2344
- let startIndex = keys.indexOf($$.getCellValue(row, getStart));
2345
- let endIndex = keys.indexOf($$.getCellValue(row, getEnd));
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));
2346
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%)`;
2347
2342
  let flags = getFlags();
2348
2343
  return /*#__PURE__*/_react.default.createElement(_rRangeSlider.default, {
@@ -2583,19 +2578,26 @@ function ATFN({
2583
2578
  eval(evalText);
2584
2579
  return model;
2585
2580
  },
2586
- getCellValue: (row, getValue) => {
2581
+ getValueByField: (row, column, getValue) => {
2582
+ let props = getProps();
2583
+ let type = typeof getValue;
2584
+
2587
2585
  try {
2588
- if (typeof getValue === 'function') {
2589
- return getValue(row);
2586
+ if (type === 'function') {
2587
+ return getValue(row, column);
2590
2588
  }
2591
2589
 
2592
- if (typeof getValue === 'string') {
2593
- let result;
2594
- eval('result = row.' + getValue);
2595
- 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;
2596
2598
  }
2597
2599
 
2598
- return;
2600
+ return getValue;
2599
2601
  } catch {
2600
2602
  return;
2601
2603
  }
@@ -2611,6 +2613,13 @@ function ATFN({
2611
2613
  column.sort = { ...column.sort,
2612
2614
  ...obj
2613
2615
  };
2616
+
2617
+ if (!column.sort.onChange && column.storageKey) {
2618
+ column = $$.updateStorageByColumn(column, {
2619
+ sort: column.sort
2620
+ });
2621
+ }
2622
+
2614
2623
  let newColumns = columns.map((o, i) => i === colIndex ? column : o);
2615
2624
  let approve = true;
2616
2625
 
@@ -2660,7 +2669,7 @@ function ATFN({
2660
2669
  let {
2661
2670
  getValue = column.getValue
2662
2671
  } = sort;
2663
- let value = $$.getCellValue(row, getValue);
2672
+ let value = $$.getValueByField(row, column, getValue);
2664
2673
 
2665
2674
  if (typeof value !== 'string') {
2666
2675
  return 0;
@@ -2723,16 +2732,9 @@ function ATFN({
2723
2732
  let column = { ...obj.column,
2724
2733
  show: !obj.column.show
2725
2734
  };
2726
-
2727
- if (column.storageKey) {
2728
- column = { ...column,
2729
- _storageObj: { ...column._storageObj,
2730
- show: column.show
2731
- }
2732
- };
2733
- localStorage.setItem('aio-table-column-storage-' + column.storageKey, JSON.stringify(column._storageObj));
2734
- }
2735
-
2735
+ column = $$.updateStorageByColumn(column, {
2736
+ show: column.show
2737
+ });
2736
2738
  setState({
2737
2739
  columns: columns.map((o, i) => i === column.realIndex ? column : o)
2738
2740
  });
@@ -2798,10 +2800,27 @@ function ATFN({
2798
2800
  column.width = storageObj.width;
2799
2801
  }
2800
2802
 
2803
+ if (storageObj.sort !== undefined) {
2804
+ column.sort = storageObj.sort;
2805
+ }
2806
+
2801
2807
  column._storageObj = storageObj;
2802
2808
  }
2803
2809
  },
2804
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
+
2805
2824
  getDetails() {
2806
2825
  let {
2807
2826
  columns,
@@ -2952,7 +2971,7 @@ function ATFN({
2952
2971
 
2953
2972
  if (storageActive === null) {
2954
2973
  storageActive = true;
2955
- localStorage.setItem('aio table group' + storageKey, JSON.stringify(storageAtive));
2974
+ localStorage.setItem('aio table group' + storageKey, JSON.stringify(storageActive));
2956
2975
  } else {
2957
2976
  storageActive = JSON.parse(storageActive);
2958
2977
  }
@@ -3263,7 +3282,7 @@ function ATFN({
3263
3282
 
3264
3283
  for (let i = 0; i < columns.length; i++) {
3265
3284
  let column = columns[i];
3266
- let value = $$.getCellValue(row, column.getValue);
3285
+ let value = $$.getValueByField(row, column, column.getValue);
3267
3286
  row._values[column.realIndex] = value;
3268
3287
 
3269
3288
  if (show && column.search && searchText) {
@@ -3436,7 +3455,7 @@ function ATFN({
3436
3455
  let childs = [];
3437
3456
 
3438
3457
  if (getRowChilds) {
3439
- childs = $$.getCellValue(row, getRowChilds) || [];
3458
+ childs = $$.getValueByField(row, undefined, getRowChilds) || [];
3440
3459
  row._childsLength = childs.length;
3441
3460
  }
3442
3461
 
@@ -3508,8 +3527,8 @@ function ATFN({
3508
3527
  continue;
3509
3528
  }
3510
3529
 
3511
- let aValue = $$.getCellValue(a, getValue),
3512
- bValue = $$.getCellValue(b, getValue);
3530
+ let aValue = $$.getValueByField(a, undefined, getValue),
3531
+ bValue = $$.getValueByField(b, undefined, getValue);
3513
3532
 
3514
3533
  if (aValue < bValue) {
3515
3534
  return -1 * (dir === 'dec' ? -1 : 1);
@@ -3626,7 +3645,7 @@ function ATFN({
3626
3645
  for (let i = 0; i < roots.length; i++) {
3627
3646
  let root = roots[i];
3628
3647
  var obj = newModel;
3629
- 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));
3630
3649
 
3631
3650
  for (let j = 0; j < values.length; j++) {
3632
3651
  let value = values[j];
@@ -3717,8 +3736,9 @@ function ATFN({
3717
3736
  getFullCellStyle: $$.getFullCellStyle,
3718
3737
  getNoData: $$.getNoData,
3719
3738
  getSortsFromColumns: $$.getSortsFromColumns,
3720
- getCellValue: $$.getCellValue,
3721
- setCellValue: $$.setCellValue
3739
+ getValueByField: $$.getValueByField,
3740
+ setCellValue: $$.setCellValue,
3741
+ updateStorageByColumn: $$.updateStorageByColumn
3722
3742
  };
3723
3743
  }
3724
3744
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-table",
3
- "version": "7.0.1",
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": {