Commit 3d55b0d45bfbaf4069e031a5d195ad7179ed6249

Authored by Leo Caan (陈栋)
Committed by GitHub
1 parent 573a4430

fix: 修复Table当dataIndex为数组时,列设置中勾选列是否展示时使column结构异常的问题 (#1626)

src/components/Table/src/hooks/useColumns.ts
... ... @@ -197,7 +197,7 @@ export function useColumns(
197 197 * set columns
198 198 * @param columnList key|column
199 199 */
200   - function setColumns(columnList: Partial<BasicColumn>[] | string[]) {
  200 + function setColumns(columnList: Partial<BasicColumn>[] | (string | string[])[]) {
201 201 const columns = cloneDeep(columnList);
202 202 if (!isArray(columns)) return;
203 203  
... ... @@ -210,23 +210,23 @@ export function useColumns(
210 210  
211 211 const cacheKeys = cacheColumns.map((item) => item.dataIndex);
212 212  
213   - if (!isString(firstColumn)) {
  213 + if (!isString(firstColumn) && !isArray(firstColumn)) {
214 214 columnsRef.value = columns as BasicColumn[];
215 215 } else {
216   - const columnKeys = columns as string[];
  216 + const columnKeys = (columns as (string | string[])[]).map(m => m.toString());
217 217 const newColumns: BasicColumn[] = [];
218 218 cacheColumns.forEach((item) => {
219 219 newColumns.push({
220 220 ...item,
221   - defaultHidden: !columnKeys.includes(item.dataIndex! || (item.key as string)),
  221 + defaultHidden: !columnKeys.includes(item.dataIndex?.toString() || (item.key as string))
222 222 });
223 223 });
224 224 // Sort according to another array
225 225 if (!isEqual(cacheKeys, columns)) {
226 226 newColumns.sort((prev, next) => {
227 227 return (
228   - columnKeys.indexOf(prev.dataIndex as string) -
229   - columnKeys.indexOf(next.dataIndex as string)
  228 + columnKeys.indexOf(prev.dataIndex?.toString() as string) -
  229 + columnKeys.indexOf(next.dataIndex?.toString() as string)
230 230 );
231 231 });
232 232 }
... ...