@hi-ui/table 4.12.1 → 4.12.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @hi-ui/table
2
2
 
3
+ ## 4.12.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3382](https://github.com/XiaoMi/hiui/pull/3382) [`144de50f5`](https://github.com/XiaoMi/hiui/commit/144de50f528c834942d1d04467f7234c1710f758) Thanks [@zyprepare](https://github.com/zyprepare)! - fix(table): 统计行加上表头分组情况的处理 (#3381)
8
+
9
+ - Updated dependencies [[`d5b4363`](https://github.com/XiaoMi/hiui/commit/d5b4363888ebc0869a70482de2eb114326ee4d3c)]:
10
+ - @hi-ui/core@4.0.10
11
+
3
12
  ## 4.12.1
4
13
 
5
14
  ### Patch Changes
@@ -132,6 +132,8 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
132
132
  }, [embedExpandable, getEmbedPanelColumn, columns]);
133
133
  var i18n = core.useLocaleContext();
134
134
  var _useMemo = React.useMemo(function () {
135
+ var _a;
136
+ // 确保包含 avg 属性,且值为数字类型的字符串
135
137
  // 确保包含 avg 属性,且值为数字类型的字符串
136
138
  var avgRow = {
137
139
  id: 'avg',
@@ -140,9 +142,15 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
140
142
  }
141
143
  };
142
144
  var hasAvgColumn = false;
143
- columns.forEach(function (column, index$1) {
144
- // 行选中模式下,index=0是checkbox列,index=1才是第一列 ; fix issue: https://github.com/XiaoMi/hiui/issues/2863
145
- if (index$1 === 0 || index$1 === 1 && columns[0].dataKey === Table.SELECTION_DATA_KEY) {
145
+ var flattenedColumns = index.flattenColumns(columns);
146
+ // 找第一个非选择框列
147
+ // 找第一个非选择框列
148
+ var firstDataColumnIndex = 0;
149
+ if (((_a = columns[0]) === null || _a === void 0 ? void 0 : _a.dataKey) === Table.SELECTION_DATA_KEY) {
150
+ firstDataColumnIndex = 1;
151
+ }
152
+ flattenedColumns.forEach(function (column, index$1) {
153
+ if (index$1 === firstDataColumnIndex) {
146
154
  // @ts-ignore
147
155
  avgRow.raw[column.dataKey] = i18n.get('table.average');
148
156
  }
@@ -161,6 +169,8 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
161
169
  avgRow = _useMemo.avgRow,
162
170
  hasAvgColumn = _useMemo.hasAvgColumn;
163
171
  var _useMemo2 = React.useMemo(function () {
172
+ var _a;
173
+ // 确保包含total属性,且值为数字类型的字符串
164
174
  // 确保包含total属性,且值为数字类型的字符串
165
175
  var sumRow = {
166
176
  id: 'sum',
@@ -169,16 +179,19 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
169
179
  }
170
180
  };
171
181
  var hasSumColumn = false;
172
- columns.forEach(function (column, index$1) {
173
- if (index$1 === 0 || index$1 === 1 && columns[0].dataKey === Table.SELECTION_DATA_KEY) {
182
+ var flattenedColumns = index.flattenColumns(columns);
183
+ var firstDataColumnIndex = 0;
184
+ if (((_a = columns[0]) === null || _a === void 0 ? void 0 : _a.dataKey) === Table.SELECTION_DATA_KEY) {
185
+ firstDataColumnIndex = 1;
186
+ }
187
+ flattenedColumns.forEach(function (column, index$1) {
188
+ if (index$1 === firstDataColumnIndex) {
174
189
  // @ts-ignore
175
190
  sumRow.raw[column.dataKey] = i18n.get('table.total');
176
191
  }
177
192
  if (index.checkNeedTotalOrEvg(data, column, 'total')) {
178
193
  hasSumColumn = true;
179
- // 获取当前数据最大小数点个数,并设置最后总和值小数点
180
194
  // @ts-ignore
181
- // 获取当前数据最大小数点个数,并设置最后总和值小数点
182
195
  // @ts-ignore
183
196
  sumRow.raw[column.dataKey] = index.getTotalOrEvgRowData(data, column, false);
184
197
  }
package/lib/cjs/Table.js CHANGED
@@ -206,6 +206,12 @@ var Table = /*#__PURE__*/React.forwardRef(function (_a, ref) {
206
206
  var rowKey = getRowKeyField(rowItem);
207
207
  var checked = isCheckedRowKey(rowKey);
208
208
  var disabledCheckbox = checkRowIsDisabledCheckbox(rowItem);
209
+ if (rowItem.key === 'avg' || rowItem.key === 'sum') {
210
+ return {
211
+ node: null,
212
+ checked: false
213
+ };
214
+ }
209
215
  return {
210
216
  node: type === 'checkbox' ? ( /*#__PURE__*/React__default["default"].createElement(Checkbox__default["default"], {
211
217
  checked: checked,
@@ -223,7 +223,23 @@ var getColumnByDefaultSortOrder = function getColumnByDefaultSortOrder(columns)
223
223
  }
224
224
  return {};
225
225
  };
226
+ var flattenColumns = function flattenColumns(columns) {
227
+ var result = [];
228
+ var traverse = function traverse(cols) {
229
+ cols.forEach(function (col) {
230
+ var _a;
231
+ if ((_a = col.children) === null || _a === void 0 ? void 0 : _a.length) {
232
+ traverse(col.children);
233
+ } else {
234
+ result.push(col);
235
+ }
236
+ });
237
+ };
238
+ traverse(columns);
239
+ return result;
240
+ };
226
241
  exports.checkNeedTotalOrEvg = checkNeedTotalOrEvg;
242
+ exports.flattenColumns = flattenColumns;
227
243
  exports.getColumnByDataKey = getColumnByDataKey;
228
244
  exports.getColumnByDefaultSortOrder = getColumnByDefaultSortOrder;
229
245
  exports.getGroupItemWidth = getGroupItemWidth;
@@ -20,7 +20,7 @@ import { TableBody } from './TableBody.js';
20
20
  import { TableHeader } from './TableHeader.js';
21
21
  import { defaultLoadingIcon } from './icons/index.js';
22
22
  import { TableProvider } from './context.js';
23
- import { uuid, checkNeedTotalOrEvg, getTotalOrEvgRowData } from './utils/index.js';
23
+ import { uuid, flattenColumns, checkNeedTotalOrEvg, getTotalOrEvgRowData } from './utils/index.js';
24
24
  import { useTable } from './use-table.js';
25
25
  import { useEmbedExpand } from './hooks/use-embed-expand.js';
26
26
  import { TheadContent } from './TheadContent.js';
@@ -119,6 +119,8 @@ var BaseTable = /*#__PURE__*/forwardRef(function (_a, ref) {
119
119
  }, [embedExpandable, getEmbedPanelColumn, columns]);
120
120
  var i18n = useLocaleContext();
121
121
  var _useMemo = useMemo(function () {
122
+ var _a;
123
+ // 确保包含 avg 属性,且值为数字类型的字符串
122
124
  // 确保包含 avg 属性,且值为数字类型的字符串
123
125
  var avgRow = {
124
126
  id: 'avg',
@@ -127,9 +129,15 @@ var BaseTable = /*#__PURE__*/forwardRef(function (_a, ref) {
127
129
  }
128
130
  };
129
131
  var hasAvgColumn = false;
130
- columns.forEach(function (column, index) {
131
- // 行选中模式下,index=0是checkbox列,index=1才是第一列 ; fix issue: https://github.com/XiaoMi/hiui/issues/2863
132
- if (index === 0 || index === 1 && columns[0].dataKey === SELECTION_DATA_KEY) {
132
+ var flattenedColumns = flattenColumns(columns);
133
+ // 找第一个非选择框列
134
+ // 找第一个非选择框列
135
+ var firstDataColumnIndex = 0;
136
+ if (((_a = columns[0]) === null || _a === void 0 ? void 0 : _a.dataKey) === SELECTION_DATA_KEY) {
137
+ firstDataColumnIndex = 1;
138
+ }
139
+ flattenedColumns.forEach(function (column, index) {
140
+ if (index === firstDataColumnIndex) {
133
141
  // @ts-ignore
134
142
  avgRow.raw[column.dataKey] = i18n.get('table.average');
135
143
  }
@@ -148,6 +156,8 @@ var BaseTable = /*#__PURE__*/forwardRef(function (_a, ref) {
148
156
  avgRow = _useMemo.avgRow,
149
157
  hasAvgColumn = _useMemo.hasAvgColumn;
150
158
  var _useMemo2 = useMemo(function () {
159
+ var _a;
160
+ // 确保包含total属性,且值为数字类型的字符串
151
161
  // 确保包含total属性,且值为数字类型的字符串
152
162
  var sumRow = {
153
163
  id: 'sum',
@@ -156,16 +166,19 @@ var BaseTable = /*#__PURE__*/forwardRef(function (_a, ref) {
156
166
  }
157
167
  };
158
168
  var hasSumColumn = false;
159
- columns.forEach(function (column, index) {
160
- if (index === 0 || index === 1 && columns[0].dataKey === SELECTION_DATA_KEY) {
169
+ var flattenedColumns = flattenColumns(columns);
170
+ var firstDataColumnIndex = 0;
171
+ if (((_a = columns[0]) === null || _a === void 0 ? void 0 : _a.dataKey) === SELECTION_DATA_KEY) {
172
+ firstDataColumnIndex = 1;
173
+ }
174
+ flattenedColumns.forEach(function (column, index) {
175
+ if (index === firstDataColumnIndex) {
161
176
  // @ts-ignore
162
177
  sumRow.raw[column.dataKey] = i18n.get('table.total');
163
178
  }
164
179
  if (checkNeedTotalOrEvg(data, column, 'total')) {
165
180
  hasSumColumn = true;
166
- // 获取当前数据最大小数点个数,并设置最后总和值小数点
167
181
  // @ts-ignore
168
- // 获取当前数据最大小数点个数,并设置最后总和值小数点
169
182
  // @ts-ignore
170
183
  sumRow.raw[column.dataKey] = getTotalOrEvgRowData(data, column, false);
171
184
  }
package/lib/esm/Table.js CHANGED
@@ -191,6 +191,12 @@ var Table = /*#__PURE__*/forwardRef(function (_a, ref) {
191
191
  var rowKey = getRowKeyField(rowItem);
192
192
  var checked = isCheckedRowKey(rowKey);
193
193
  var disabledCheckbox = checkRowIsDisabledCheckbox(rowItem);
194
+ if (rowItem.key === 'avg' || rowItem.key === 'sum') {
195
+ return {
196
+ node: null,
197
+ checked: false
198
+ };
199
+ }
194
200
  return {
195
201
  node: type === 'checkbox' ? ( /*#__PURE__*/React__default.createElement(Checkbox, {
196
202
  checked: checked,
@@ -218,4 +218,19 @@ var getColumnByDefaultSortOrder = function getColumnByDefaultSortOrder(columns)
218
218
  }
219
219
  return {};
220
220
  };
221
- export { checkNeedTotalOrEvg, getColumnByDataKey, getColumnByDefaultSortOrder, getGroupItemWidth, getTotalOrEvgRowData, parseFixedColumns, parseLocalArray, setColumnsDefaultWidth, uuid };
221
+ var flattenColumns = function flattenColumns(columns) {
222
+ var result = [];
223
+ var traverse = function traverse(cols) {
224
+ cols.forEach(function (col) {
225
+ var _a;
226
+ if ((_a = col.children) === null || _a === void 0 ? void 0 : _a.length) {
227
+ traverse(col.children);
228
+ } else {
229
+ result.push(col);
230
+ }
231
+ });
232
+ };
233
+ traverse(columns);
234
+ return result;
235
+ };
236
+ export { checkNeedTotalOrEvg, flattenColumns, getColumnByDataKey, getColumnByDefaultSortOrder, getGroupItemWidth, getTotalOrEvgRowData, parseFixedColumns, parseLocalArray, setColumnsDefaultWidth, uuid };
@@ -27,3 +27,4 @@ export declare const getColumnByDataKey: (columns: TableColumnItem[], dataKey: s
27
27
  * 获取默认排序的列
28
28
  */
29
29
  export declare const getColumnByDefaultSortOrder: (columns: TableColumnItem[]) => TableColumnItem;
30
+ export declare const flattenColumns: (columns: TableColumnItem[]) => TableColumnItem[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/table",
3
- "version": "4.12.1",
3
+ "version": "4.12.2",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",
@@ -78,12 +78,12 @@
78
78
  "react-resizable": "^3.0.4"
79
79
  },
80
80
  "peerDependencies": {
81
- "@hi-ui/core": ">=4.0.8",
81
+ "@hi-ui/core": ">=4.0.10",
82
82
  "react": ">=16.8.6",
83
83
  "react-dom": ">=16.8.6"
84
84
  },
85
85
  "devDependencies": {
86
- "@hi-ui/core": "^4.0.8",
86
+ "@hi-ui/core": "^4.0.10",
87
87
  "@hi-ui/core-css": "^4.1.5",
88
88
  "@types/react-resizable": "^1.7.4",
89
89
  "react": "^17.0.1",