Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Table): 修复table fix 在表头分组中fixed固定位置错误问题 #727

Merged
merged 28 commits into from Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a196114
feat(Table): Table 新增树形数据结构展示功能 #539
cuilanxin Mar 16, 2022
ba4173c
Merge branch 'master' of github.com:uiwjs/uiw
cuilanxin Mar 17, 2022
a9b9b5f
feat(Table): Table 新增支持 align 属性 className属性 #682
cuilanxin Mar 17, 2022
03bb855
Merge branch 'master' of github.com:uiwjs/uiw
cuilanxin Mar 17, 2022
ccf7d16
Merge branch 'master' of github.com:uiwjs/uiw
cuilanxin Mar 18, 2022
8a06082
feat(Table): Table 添加 scroll 属性,解决表格冗余 div #687
cuilanxin Mar 18, 2022
a11db86
feat(Table): Table 添加 scroll 属性,解决表格冗余 div #687
cuilanxin Mar 18, 2022
f064884
Merge branch 'uiwjs:master' into master
cuilanxin Mar 20, 2022
e0dded3
Merge branch 'uiwjs:master' into master
cuilanxin Mar 21, 2022
2bb39f9
feat(Table): Table 新增固定列属性
cuilanxin Mar 21, 2022
a86201e
feat(Table): Table 新增固定列属性
cuilanxin Mar 21, 2022
e825768
Merge branch 'master' of github.com:uiwjs/uiw
cuilanxin Mar 21, 2022
35816f7
doc(Table): Update README.md
cuilanxin Mar 21, 2022
86699f6
Merge branch 'master' of github.com:uiwjs/uiw
cuilanxin Mar 22, 2022
68f8262
update(Table): Table 支持树形数据显示和可展开同时出现
cuilanxin Mar 22, 2022
90b101f
Merge branch 'uiwjs:master' into master
cuilanxin Mar 22, 2022
a9d6ba7
Merge branch 'uiwjs:master' into master
cuilanxin Mar 23, 2022
fab96bd
fix(Table): 修复Table indentSize 传递0失效问题
cuilanxin Mar 23, 2022
fe440e6
Merge branch 'uiwjs:master' into master
cuilanxin Mar 23, 2022
343aef7
Merge branch 'uiwjs:master' into master
cuilanxin Mar 25, 2022
5a5bbdd
fix(Table): 修复 table fixed 不能对表头分组使用
cuilanxin Mar 25, 2022
2bab0b6
Merge branch 'uiwjs:master' into master
cuilanxin Mar 25, 2022
85bcab1
Merge branch 'uiwjs:master' into master
cuilanxin Mar 28, 2022
b5a2a04
Merge branch 'uiwjs:master' into master
cuilanxin Mar 28, 2022
980e4ec
Merge branch 'uiwjs:master' into master
cuilanxin Mar 30, 2022
2c9f85f
fix(Table): 修复table fix 在表头分组中fixed固定位置错误问题
cuilanxin Mar 30, 2022
f7d8831
fix(Table): 修复table fix 在表头分组中fixed固定位置错误问题
cuilanxin Mar 30, 2022
64da40d
fix(Table): 修复table fix 在表头分组中fixed固定位置错误问题
cuilanxin Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/react-table/README.md
Expand Up @@ -80,6 +80,11 @@ const columns = [
style: { color: 'red' },
key: 'name',
children: [
{
title: '英文名字',
width: 100,
key: 'name_en',
},
{
title: '中文名字',
key: 'cnname',
Expand All @@ -90,7 +95,7 @@ const columns = [
key: 'firstname',
children:[
{ title: '姓', key: 'name1', width: 80 },
{ title: '名', key: 'name2', width: 80 },
{ title: '名', key: 'name2', width: 80 },
]
}, {
title: '拼音',
Expand All @@ -101,14 +106,11 @@ const columns = [
],
},
],
}, {
title: '英文名字',
width: 100,
key: 'name_en',
},
},
]
}, {
title: '其它',
key: 'other',
children:[
{ title: '生日', key: 'birthday', width: 150 },
{ title: '职业', key: 'job', width: 150 },
Expand Down
15 changes: 10 additions & 5 deletions packages/react-table/src/TableTr.tsx
Expand Up @@ -115,9 +115,9 @@ export default function TableTr<T extends { [key: string]: any }>(props: TableTr
}
if (keyName.fixed) {
if (keyName.fixed === 'right') {
objs.className = `${objs.className} ${prefixCls}-fixed-right`;
objs.className = `${prefixCls}-fixed-right`;
} else {
objs.className = `${objs.className} ${prefixCls}-fixed-true`;
objs.className = `${prefixCls}-fixed-true`;
}
}
return (
Expand All @@ -134,9 +134,14 @@ export default function TableTr<T extends { [key: string]: any }>(props: TableTr
</span>
}
key={colNum}
className={`${prefixCls}-tr-children-${keyName.align || 'left'} ${keyName.className || ''} ${
objs.className || ''
}`}
className={[
prefixCls + '-tr-children-' + (keyName.align || 'left'),
keyName.className,
objs.className,
]
.filter((it) => it)
.join(' ')
.trim()}
onClick={(evn) => onCell(trData, { rowNum, colNum, keyName: keyName.key! }, evn)}
/>
);
Expand Down
63 changes: 28 additions & 35 deletions packages/react-table/src/index.tsx
Expand Up @@ -118,54 +118,46 @@ export default function Table<T extends { [key: string]: V }, V>(props: TablePro
setLocationWidth(computed());
}
};
const deepClumnsLocation = (
params: Array<TableColumns<T> | number>,
fistIndex: number,
leftOrRight: 'left' | 'right',
isReverse: boolean,
) => {
const deepClumnsLocation = (params: Array<TableColumns<T> | number>, fistIndex: number) => {
let initialValue = 0,
lastIndex = isReverse ? 0 : params.length - 1,
headerIndex = 0,
deepParams: Array<TableColumns<T> | number> = [];
params.forEach(() => {
let abs = Math.abs(lastIndex);
const i = `${fistIndex}${abs}`;
if (isReverse) {
lastIndex += 1;
} else {
lastIndex -= 1;
}
if (typeof params[abs] === 'number') {
initialValue = (params[abs] as number) + initialValue;
deepParams.push(params[abs]);
params.forEach((_, index) => {
const i = `${fistIndex}${headerIndex}`;
if (typeof params[index] === 'number') {
initialValue = (params[index] as number) + initialValue;
deepParams.push(params[index]);
return;
}
if (finalLocationWidth.current[i]) {
finalLocationWidth.current[i][leftOrRight] = initialValue;
finalLocationWidth.current[i].left = initialValue;
initialValue = finalLocationWidth.current[i].width + initialValue;
if (Array.isArray((params[index] as TableColumns<T>).children)) {
deepParams.push(...(params[index] as TableColumns<T>).children!);
} else {
deepParams.push(finalLocationWidth.current[i].width);
}
}
if (Array.isArray((params[abs] as TableColumns<T>).children)) {
deepParams.push(...(params[abs] as TableColumns<T>).children!);
return;
headerIndex += 1;
});
(initialValue = 0), (headerIndex = header[fistIndex].length - 1);
for (let index = params.length - 1; index >= 0; index--) {
const i = `${fistIndex}${headerIndex}`;
if (typeof params[index] === 'number') {
initialValue = (params[index] as number) + initialValue;
continue;
}
if (finalLocationWidth.current[i]) {
deepParams.push(finalLocationWidth.current[i].width);
} else {
const parent = header.find((it) => it.find((it) => it.key === (params[abs] as TableColumns<T>).key)) || [];
const sub = parent.findIndex((it) => it.key === (params[abs] as TableColumns<T>).key);
if (finalLocationWidth.current[`${i[0]}${sub}`]) {
// 合并单元格
deepParams.push(finalLocationWidth.current[`${i[0]}${sub}`].width);
}
finalLocationWidth.current[i].right = initialValue;
initialValue = finalLocationWidth.current[i].width + initialValue;
}
});
if (deepParams.filter((it) => typeof it !== 'number').length)
deepClumnsLocation(deepParams, fistIndex + 1, leftOrRight, isReverse);
headerIndex -= 1;
}
if (deepParams.filter((it) => typeof it !== 'number').length) deepClumnsLocation(deepParams, fistIndex + 1);
};

const computed = () => {
deepClumnsLocation(columns, 0, 'left', true);
deepClumnsLocation(columns, 0, 'right', false);
deepClumnsLocation(columns, 0);
return finalLocationWidth.current;
};
useEffect(() => {
Expand Down Expand Up @@ -296,6 +288,7 @@ export default function Table<T extends { [key: string]: V }, V>(props: TablePro
}, [scroll]);
const cls = [prefixCls, className, bordered ? `${prefixCls}-bordered` : null].filter(Boolean).join(' ').trim();
const { header, render, ellipsis } = getLevelItems(self.selfColumns);

return (
<React.Fragment>
<div className={cls} {...other} style={{ ...other.style, ...style.div }}>
Expand Down