-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6033634
commit 52bb3f9
Showing
6 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/semi-ui/table/_story/v2/FixedOnGroupedRowClassName/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from 'react'; | ||
import { Table, Avatar } from '@douyinfe/semi-ui'; | ||
import * as dateFns from 'date-fns'; | ||
|
||
const DAY = 24 * 60 * 60 * 1000; | ||
const figmaIconUrl = 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png'; | ||
|
||
export default function App() { | ||
const getData = () => { | ||
const data = []; | ||
for (let i = 0; i < 46; i++) { | ||
const isSemiDesign = i % 2 === 0; | ||
const randomNumber = ((i * 1000) % 19) + 100; | ||
data.push({ | ||
key: '' + i, | ||
name: isSemiDesign ? `Semi Design 设计稿${i}.fig` : `Semi D2C 设计稿${i}.fig`, | ||
owner: isSemiDesign ? '姜鹏志' : '郝宣', | ||
size: randomNumber, | ||
updateTime: new Date().valueOf() + randomNumber * DAY, | ||
avatarBg: isSemiDesign ? 'grey' : 'red', | ||
}); | ||
} | ||
return data; | ||
}; | ||
|
||
const data = getData(); | ||
const columns = [ | ||
{ | ||
title: '标题', | ||
dataIndex: 'name', | ||
width: 400, | ||
render: (text, record, index) => { | ||
return ( | ||
<div> | ||
<Avatar size="small" shape="square" src={figmaIconUrl} style={{ marginRight: 12 }}></Avatar> | ||
{text} | ||
</div> | ||
); | ||
}, | ||
filters: [ | ||
{ | ||
text: 'Semi Design 设计稿', | ||
value: 'Semi Design 设计稿', | ||
}, | ||
{ | ||
text: 'Semi D2C 设计稿', | ||
value: 'Semi D2C 设计稿', | ||
}, | ||
], | ||
onFilter: (value, record) => record.name.includes(value), | ||
}, | ||
{ | ||
title: '大小', | ||
dataIndex: 'size', | ||
sorter: (a, b) => (a.size - b.size > 0 ? 1 : -1), | ||
render: text => `${text} KB`, | ||
}, | ||
{ | ||
title: '所有者', | ||
dataIndex: 'owner', | ||
render: (text, record, index) => { | ||
return ( | ||
<div> | ||
<Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}> | ||
{typeof text === 'string' && text.slice(0, 1)} | ||
</Avatar> | ||
{text} | ||
</div> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: '更新日期', | ||
dataIndex: 'updateTime', | ||
sorter: (a, b) => (a.updateTime - b.updateTime > 0 ? 1 : -1), | ||
render: value => { | ||
return dateFns.format(new Date(value), 'yyyy-MM-dd'); | ||
}, | ||
}, | ||
]; | ||
const rowKey = record => | ||
`${record.owner && record.owner.toLowerCase()}-${record.name && record.name.toLowerCase()}`; | ||
|
||
return ( | ||
<div style={{ padding: '20px 0px' }}> | ||
<Table | ||
dataSource={data} | ||
rowKey={rowKey} | ||
groupBy={'size'} | ||
columns={columns} | ||
renderGroupSection={groupKey => <strong>根据文件大小分组 {groupKey} KB</strong>} | ||
onGroupedRow={(group, index) => { | ||
return { | ||
className: 'test-group', | ||
onClick: e => { | ||
console.log(`Grouped row clicked: `, group, index); | ||
}, | ||
}; | ||
}} | ||
clickGroupedRowToExpand // if you want to click the entire row to expand | ||
scroll={{ y: 480 }} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters