2.9.1
๋ธ๋ผ์ฐ์
ํ ์ด๋ธ ๋ฐ๋ฅ ๊ธ์ ์ง๊ณ ํต๊ณ๋ฅผ ํ์ํ๊ณ ์ถ์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ์ ์๋ํ๊ณ ์์ต๋๋ค.
footer
์ํ์ ์ฌ์ฉํ์ฌ tr
๋ฐ td
<Table
dataSource={dataSource}
footer={() => {
return (
<tr className='ant-table-row ant-table-row-level-0'>
<td>ๆป่ฎก</td>
<td>ๆป่ฎก</td>
<td>ๆป่ฎก</td>
</tr>
)
}}
/>
dataSource
์ํ์ ์ถ๊ฐ ๋ฐ์ดํฐ ์ถ๊ฐdataSource.push({id: 'ๆป่ฎก', price: '3000'})
์ฌ์ง์ ์ฒ ๋จ์ด์ ๊ฐ์น๊ฐ ์์ต๋๋ค.
footer
์ํ์ ์ฌ์ฉํ์ง๋ง footer
์ํ์ ํ
์ด๋ธ tbody์ ๋ง์ง ์์ต๋๋ค.
dataSource
prop์ ์ถ๊ฐ ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ์ง๋ง dataSource ๊ธธ์ด๊ฐ pageSize
์ด๊ณผํ๋ฉด ์ถ๊ฐ ๋ฐ์ดํฐ๊ฐ ๋ฌด์๋ฉ๋๋ค.
@TangMonk ์๋ ํ์ธ์. ๋ฒ๊ทธ๋ณด๊ณ ๋ณด๋ค ๊ธฐ๋ฅ์ ์์ฒญํ๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ฃ์กํ์ง๋ง์ด ๊ธฐ๋ฅ์ ๊ตฌํํ ๊ณํ์ด ์์ต๋๋ค. ํ ์ด๋ธ์ ๊ธฐ๋ณธ ํ์ด์ง ๋งค๊น์ ๋นํ์ฑํํ๊ณ ์ง์ ํ์ด์ง ๋งค๊น์ ๊ตฌํํ ์ ์์ต๋๋ค.
footer
ํ
์ด๋ธ์ ๋ง๊ฒ ๋ญ๊ฐ๋ฅผ ํ ์ ์์๊น์?
@yesmeck , ๋ต์ฅ์ ๋ณด๋ด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.ํ์ง๋ง ์ด๊ฒ์ ๋ํด ๋๋ฌด ๋ง์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.์ด ๊ธฐ๋ฅ์ด ์ ๋ง ์ ์ฉํ๊ณ ํ์ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
๊ด๋ จ ๋ฌธ์ : # 3591, # 1483, # 4581
@ afc163 , ๊ฐ์ฌํฉ๋๋ค!
๋น์ ์ ์ ์์ด๋ ํด๊ฒฐ์ฑ ์ ๋ฌด์์ ๋๊น?
ํ์คํ์ง ์์ต๋๋ค. pageSize
๋ฅผ ์ฌ์ฉํ์ฌ ํ
์ด๋ธ ๋ฐ์ดํฐ ํฌ๊ธฐ๋ฅผ ์ ํ ํ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋ฐ์ดํฐ๋ ํด๋ผ์ด์ธํธ ์ธก์ด ์๋ ์๋ฒ ์ธก์์ ์ฒ๋ฆฌํด์ผํ๋ฏ๋ก ํ
์ด๋ธ์ ์ถ๊ฐ ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐ ํ ์ ์์ต๋๋ค.
์๋
ํ์ธ์,
์ด ๊ธฐ๋ฅ์ ๋ํ ์
๋ฐ์ดํธ๊ฐ ์์ต๋๊น? ์๋๋ฉด ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก?
@yesmeck ๊ฐ์ฅ ๊ฐ๋จํ ํด๊ฒฐ์ฑ
์ ํ
์ด๋ธ ์ธ๋ถ์ ์ถ๊ฐ <div>
๋ฅผ ์ถ๊ฐํ๋ ๋์ ๋ฐ๋ฅ ๊ธ์ด ํ
์ด๋ธ ๋ด๋ถ์ ์ค์ <tfoot>
๋ ๋๋งํ๋๋กํ๋ ๊ฒ์
๋๋ค.
์ฌ๋๋ค์ ๋จ์ํ ํ
์ด๋ธ ๋ ์ด์์์ด ์ด์ ์ ๋ ฌํ๊ธฐ๋ฅผ ์ํ๊ธฐ ๋๋ฌธ์ ์ถ๊ฐ ํ์ dataSource
์ ์ง๋ด๋ ค๊ณ ํฉ๋๋ค.
์, ์ด๋ฏธ footer
prop์ด ์์ต๋๋ค. <tfoot/>
์ ์ ์ ํ ์ด๋ฆ์ ์ฐพ์ ์ ์์ต๋๋ค.
์๋ก์ด tfoot
์ํ์ ์ถ๊ฐํ์ง ์๊ณ ํ
์ด๋ธ ๋ด๋ถ์ <tfoot />
๋ ๋๋งํ๋๋ก ํ์ฌ footer
์ํ์ ๋ค์ ๊ตฌํํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ๊ทธ๊ฒ์ด ์๋ฌด๊ฒ๋ ๋ง์น ๊ฒ์ด๋ผ๊ณ ์๊ฐํ์ง ๋ง์ญ์์ค.
@yesmeck ์ด ๊ธฐ๋ฅ์ด ์์ฃผ ์์ฒญ๋๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ํ ์์ฝ ํ์ ์ถ๊ฐํ๋ ๋ฐ ์ด๋ ค์์ ๊ฒช๊ณ ์์ต๋๋ค. ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์์ง๋ง ํดํค ๋ ์กฐ์์ด ํฌํจ๋์ด ๋ ์์ ์๋ฃจ์ ์ ๋ณด๊ฒ๋์ด ๊ธฐ์ฉ๋๋ค.
์ด๋ฏธ ์ฒ๋ฆฌํ๊ณ ์๋ ํ์์ด ์๋์? ๋ง์ฝ ์๋๋ผ๋ฉด ๋ด๊ฐ ์กฐ์ฌ ํ ์์์ ๊ฒ์ ๋๋ค.
PR์ ์๋ ํ ์ ์์ต๋๋ค.
@yesmeck ์ฌ๊ธฐ ์์ต๋๋ค : https://github.com/react-component/table/pull/191
ํจ๊ณผ๋ example / renderFooterInTable์ ์ฐธ์กฐํ์ญ์์ค.
tfoot
API์ ๋ํด ์ ์ ์๊ฐํ ํ column
์์ฑ์ ์ถ๊ฐํ๊ณ ์ถ์ต๋๋ค.
const columns = [{
title: 'Age',
dataIndex: 'age',
key: 'age',
footer: (data) => {
return <div>Summary: {data.reduce((sum, record) => sum + record.age, 0)}</div>
},
}, {
title: 'Name',
dataIndex: 'name',
key: 'name',
}, {
title: 'Address',
dataIndex: 'address',
key: 'address',
}];
๋ ๋๋ง
ํ์ฌ Table[footer]
๊ฐ์ ์ฐจ์ด๋ฅผ ๋ง๋๋ ๊ฒ์ด ๋ ๋ถ๋ช
ํฉ๋๋ค.
์ข์ ์๊ฐ. ๋๋ ์ด๊ฒ์ด ์๋ก์ด API๋ฅผ ์ง๊ธฐ์ ๋ ์ข์ ๊ณณ์ด๋ผ๋ ๋ฐ ๋์ํฉ๋๋ค.
@hackape ์๋ก์ด PR์ ์ ์ ํ ์ ์์ต๋๊น?
ํ์คํ ๊ฒ
https://codesandbox.io/s/m45r6o4nj8
๋ฌ์ฑํ์ง๋ง ์คํฌ๋กค๋ฐ ์ฐ๋์ ๋ฌธ์ ๊ฐ์์ด๋ณด๊ธฐ๊ฐ ๋ ํธ๋ฆฌํฉ๋๋ค
@yesmeck react-component / table # 195์ ์ํ๋ ์ด๋ป์ต๋๊น? ํผ๋๋ฐฑ์ด ์์ต๋๊น?
ํฉ์ณ ๋ดค์ด์ ๐ @yesmeck
๊ทธ๋ฌ๋ ์ถ๊ฐ ๊ธฐ๋ฅ ์์ฒญ์ด ์์ต๋๋ค. ํ ๋จธ๋ฆฌ๊ธ ๋ฐ๋ก ์๋ ํ ์๋จ์ ์์ "๋ฐ๋ฅ ๊ธ"์ด ํ์๋๋๋ก ์ ์ํ๊ณ ์ถ์ต๋๋ค.
์:
์ค์ ์์ฒญ ๊ธฐ๋ฅ์ ์กด์ฌ๋์ ๋ด์ฉ์ ํผ์ํ์ง ์๊ณ , ์ ์ฒด ์๊ฐ ํต๊ณ ์ ๋ณด - ๋ค๋ฅธ ๋จ์ด๋ "์์ฝ ํ"์ ํ์ํ๊ธฐ์ํ ๋ณ๋์ ํ์ ์ง์ด ๋ฃ์ ๊ฒ์ด ํ๊ท ์
๋๋ค ๋
ผ์ dataSource
์์๊ฐ ์๋ "๋ฐ๋ฅ ๊ธ" ์์น ๊ฐ๊ฐ.
@hackape ์ด ๊ทธ๋ฃนํ๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. https://codesandbox.io/s/pmorq2x2lq๋ฅผ ์ฐธ์กฐ
์, ํฌ์ง์ ๋ ๋ชฉ์ ์ผ๋ก ๋ง ์ฌ์ฉํ๋ค๋ฉด ์คํ ๊ฐ๋ฅํ ์๋จ์ด ๋ ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ ๋น์ฆ๋์ค ๋ก์ง ์ธก๋ฉด์์ ์ฌ์ฉ์๊ฐ ์ ์ํ API๋ฅผ ํตํด ์ํํ๋๋กํ๋ ๊ฒ์ด ๋ ์ข์ต๋๋ค.
column.footer
API์ ์ด๋ฆ์ column.summary
๋ฐ๊ฟ ์ ์์ต๋๋ค.
const columns = [{
title: 'Age',
dataIndex: 'age',
key: 'age',
summary: {
render: (data) => {
return <div>Summary: {data.reduce((sum, record) => sum + record.age, 0)}</div>
},
position: 'bottom', // default to 'bottom', could be 'top'
}
}]
@yesmeck ๊ณ ๋ ค https://github.com/ant-design/ant-design/issues/6896
pinnedTopData
๋ฐ pinnedBottomData
๋ผ๋ ๋ ๋ช
์ ์๋ก์ด ํ๋ก๋ฅผ ์๊ฐ ํ ๊ฒ์ ์ ์ํฉ๋๋ค.
const columns = [
{ title: 'Price', dataIndex: 'price' },
{ name: 'Name', dataIndex: 'name' },
];
const data = [
{ price: 3, Name: 'Foo' },
{ price: 5, Name: 'Bar' },
];
const pinnedData = [
{ price: <span style={{ fontWeight: 'bold' }}>Total: 8</span> }
];
<Table
columns={columns}
dataSource={data}
pinnedTopData={pinnedData}
pinnedBottomData={pinnedData}
/>
๋ ๋๋ง :
| ๊ฐ๊ฒฉ | ์ด๋ฆ |
| ---------- | ------ |
| ํฉ๊ณ : 8 | |
| 3 | Foo |
| 5 | ๋ฐ |
| ํฉ๊ณ : 8 | |
๋์ผํ API๋ก # 6896๊ณผ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
์๋ก์ด ์ง์ ์ด ์์ต๋๊น?
@Nokecy ๋ ๊ทธ์ ์๋ฃจ์
์ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก ๋ด
๋๋ค. ๊ทธ๋ ์ผ์์ ์ผ๋ก ์์ฑ์ ์ถ๊ฐํ์ง ์์์ต๋๋ค. ๋ฒ์ ๋ฒํธ๊ฐ ์ต์ ๋ฒ์ ์ผ๋ก ์
๊ทธ๋ ์ด๋๋๋ฉด ๊ทธ์ re-table์์ด ์์ฑ์ด ์๋ค๊ณ ์๊ฐํ์ง๋ง antd ํจํค์ง๋ฅผ ์์ ํด์ผํฉ๋๋ค. .json. ๋ํ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ,
1. ์ด์ด ๋ง์ง ์๊ณ ์คํฌ๋กค๋ฐ๊ฐ ๋ํ๋์ง ์์ผ๋ฉด ์ฝ๊ฒ ํด๊ฒฐํ ์ ์์ผ๋ฉฐ ์์ ์๊ฐ ์์ต๋๋ค.
2. ์ฌ๋ฌ ๊ฐ์ ์ ๋ชฉ ํ์ ์ค์ ์ฌ์ฉํ์ฌ ํ์ ํ ์ ์์ง๋ง ๋๋ฌด ์๋ฆ๋ต ์ง ์์ต๋๋ค.
๋๋ ๊ทธ๋ค์ด์ด ๊ธฐ๋ฅ์ ๊ฐ์ ํ๊ธฐ๋ฅผ ๊ธฐ๋ํ๊ณ ์ฃผ์๋ฅผ ๊ธฐ์ธ์ด๊ณ ์์ง๋ง ์ฐ๋ฆฌ์ antd๋ 2 ์ ๋๋ค. ์ ๋ฐ์ดํธํ๋๋ผ๋ 2. ๋ฒ์ ์์ด ์์ฑ์ด
์ด ๋ฌธ์ ์ ๋ํ ์ ๋ฐ์ดํธ ??
๊ณต์ API๋ฅผ ์ ๊ณตํ๊ธฐ ์ ์ ์ง๊ธ์ table.props.components.body.wrapper
์ฌ์ฉ์ ์ง์ ๊ตฌ์ฑ ์์๋ฅผ ์ ๊ณตํ๊ณ ๋ฐ์ props.children
๋ณ์กฐํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
https://codesandbox.io/s/xpvwpx0npw
dom ์์๋ฅผ ์ง์ ์กฐ์ํ๊ณ ํฉ๊ณ๋ฅผ ์บก์ํํ์ต๋๋ค.์ด ๋ฐฉ๋ฒ์ ๋ฐ๋ผ ํธํฐ๋ฅผ ๋ง์ด ์ถ๊ฐ ํ ์ ์์ง๋ง ๊ณต์์ ์ผ๋ก๋ dom ์์์ ๋ํ ์ง์ ์กฐ์์ ๊ถ์ฅํ์ง ์์ต๋๋ค. ๊ธํ ํ์ํ ๊ฒฝ์ฐ ์ฐธ๊ณ ํ ์ ์์ต๋๋ค.
@ LDD123 ์คํฌ๋กค x๋ ๊ทํ์ ์์ ์์ ๋ฐ๋ฅ ๊ธ์๋ง ์์ต๋๋ค. ๋ณธ๋ฌธ๋ ๋ฐ๋ฅ ๊ธ๊ณผ ํจ๊ป ์คํฌ๋กค๋์ด์ผํฉ๋๋ค.
@jagratiTomar ๋ฐ๋ฅ ๊ธ์ด ์คํฌ๋กค ๋ ๋ ๋ณธ๋ฌธ์ด ์คํฌ๋กค๋ฉ๋๋ค. ๋ณธ๋ฌธ์ scroll-x๋ฅผ ๋ฐ๋ฅ ๊ธ์ scroll-x์ ๋ฐ์ธ๋ฉํฉ๋๋ค.
@ LDD123 ์ ๋ณธ๋ฌธ์ scroll-y๊ฐ์๋ ๊ฒฝ์ฐ ๊ณต์ ํ๊ณ ์๋ฅผ ๋ค์ด
@jagratiTomar ์ง๊ธ, ์คํฌ๋กค์ด ์๋ ์คํฌ๋กค -x๋ฅผ ์จ๊ฒผ์ต๋๋ค.
@ LDD123 ๊ทธ๋์ scroll-y๊ฐ์์ ๋์ด ์์ ๊ฐ ์ ๋๋ก ์๋ํ๋ค๊ณ ๋งํ๊ณ ์์ต๋๊น?
์
์๋ ํ์ธ์ @yesmeck @ afc163 ,
๋์์ด๋๋ UX ๋ชฉ์ ์ ์ํด ๋ณธ๋ฌธ ์๋จ๊ณผ ๋จธ๋ฆฌ๊ธ ๋ฐ๋ก ์๋์ ๋ฐ๋ฅ ๊ธ (์ง๊ณ ๋ ๊ฐ์ด ์์)์ ๋ฐฐ์นํฉ๋๋ค. ๋จธ๋ฆฌ๊ธ ๋ฐ ๋ฐ๋ฅ ๊ธ ์ ๋ ฌ์์ํ ํ์ดํ์๋ ์ง๊ณ ๋ ๊ฐ๋ง ์์ต๋๋ค. ์ ๋ ฌ์์ํ ColumnGroup ํ์ดํ๊ฐ ๋งจ ์๋์ ์ถ๊ฐ๋ฉ๋๋ค. ์คํ์ผ๋ง ๊ด์ ์์ ๋ฐ๋ฅ ๊ธ ์ปจํ ์ด๋์ ์์์ด ๋ค๋ฅด๊ณ ์ผ๋ถ ์ ์๋ง ๊ตฌ๋ถ์๊ฐ ์๊ธฐ ๋๋ฌธ์ ๋ฐ๋ฅ ๊ธ ์คํ์ผ์ ์ง์ ํ๊ณ ์๋จ์ ์ค์ ํ๋ ๊ฒ์ด ํจ์ฌ ๋ ์ฝ์ต๋๋ค.
๋๋ ๋จ์ง ํ ๊ฒ์ด๋ค :
.my-table tfoot > tr {
background-color: gray;
}
ํ ์ด๋ธ ๊ตฌ์ฑ ์์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
<Table appendColumnFooterTop={true}>
<Column
footer={(data) => <div>Summary: {data.reduce((sum, record) => sum + record.age, 0)}</div>}
/>
</Table>
๋์์ธ:
์ด์ ์ ์ํ ํ ํ์ด์ง์ ์ ์์๋ ์ ๋ ฌ๋์ง ์์ ํ ์คํธ๋ ์ฐ๋ฆฌ๊ฐ ์ฝ๋ฉํ๋ ์ ํ์ด์ง์ ์ ๋ ฌํด์ผํฉ๋๋ค.
2 ์ฃผ ๋๋ 3 ์ฃผ ์ด๋ด์ ๋ฆด๋ฆฌ์ค ๋ ์ ์๋ค๋ ๊ฒ์ ์๊ณ ์์ผ๋ฉด ๋์์ ์ค ์ ์์ต๋๋ค (์ด ๋ฐ๋ฅ ๊ธ ๋ฐ ์ ๋ ฌ). ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ค๋ฅธ ํด๊ฒฐ์ฑ ์ ์ฐพ์์ผํฉ๋๋ค.
์ ๊ทธ๋ฆฌ๊ณ # 6896์ด ์ด ๋ฐ๋ฅ ๊ธ์ ๊ดํ ๊ฒ์ธ์ง ์ดํดํ ์ ์์ด์ ์ฌ๊ธฐ์ ์ผ์ต๋๋ค.
๊ฐ์ฌ.
@kaanozcan 3 ์์ ๋์ผํ ์์ด๋์ด ( ์ฌ๊ธฐ ์ฐธ์กฐ)๋ฅผ ๊ตฌํํ๋ PR์ ์ ์ถํ๋๋ฐ ํต์ฌ ํ์ด์ด๋ฅผ ๋ณํฉ ํ ๋ค์ ๋๋ ๋ ธ์ต๋๋ค. ๋ฌธ์ ๋ฅผ ์ด๋ป๊ฒ ํด๊ฒฐํด์ผํ๋์ง์ ๋ํ ๋ค๋ฅธ ์๊ฐ์ด์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ํฉ์ ๊ฐ์ํ ๋ "๋ค๋ฅธ ์๋ฃจ์ ์ฐพ๊ธฐ"๊ฒฝ๋ก๋ฅผ ์ ํํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
@kaanozcan ๋ค์์ ์ฌ์ฉ์ ์ ์ ๊ตฌ์ฑ ์์๋ก ๋ชฉํ๋ฅผ ๋ฌ์ฑํ๋ ์์ ๋๋ค. https://codesandbox.io/s/xjpkx9rzzw
@yesmeck ์๋ฒฝํ๊ฒ ์๋ํฉ๋๋ค. ๊ฐ์ฌ.
์๋ ์์ฒญ์ผ๋ก ์ธํ ๋ง๊ฐ์ ์ฌ์ฉ์ ์ ์ ๊ตฌ์ฑ ์์๋ก ์ํ ํ ์ ์์ต๋๋ค.
@yesmeck ์ด ์ฌ์ฉ ์ฌ๋ก์ ๋ํ ๋ฐ๋ชจ๋ฅผ ์ ๊ณต ํ ์ ์์ต๋๊น?
https://codesandbox.io/s/xjpkx9rzzw
์ด ์์ ๋ ์ค์ ์ ์ธ ์๋ฏธ๊ฐ ์์ต๋๋ค. ๋ฐ์ดํฐ๊ฐ ๋ณ๊ฒฝ๋๋ฉด .. ๋ง์ง๋ง ํฉ๊ณ๋ ์ต์ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ์ง ์์ต๋๋ค. ๋ง์ง๋ง ์๋ก ๊ณ ์นจ์ ๊ฒฐ๊ณผ์
๋๋ค. ๋ํฐ ๋ฐ์ดํฐ๊ฐ์๋ ๊ณณ์ด์ด์ผํฉ๋๋ค.
@yesmeck ์ ๊ณต ํ ์์ ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค ... ๋ฐ์ดํฐ๋ฅผ ๋ณ๊ฒฝํ ์ ์๊ธฐ ๋๋ฌธ์
๋๋ค.
const data = [
{
key: "1",
name: "John Brown",
age: 30,
address: "New York No. 1 Lake Park",
},
{
key: "2",
name: "Jim Green",
age: 20,
address: "London No. 1 Lake Park",
},
{
key: "3",
name: "Joe Black",
age: Math.random() * 20,
address: "Sidney No. 1 Lake Park",
},
];
๊ฐ์ ์์ ... ์ค์ ๋ก ์ต์ข
ํฉ๊ณ๊ฐ ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.
@yesmeck https://codesandbox.io/s/xjpkx9rzzw ์ด ๋ฐ๋ชจ๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์ผ์ชฝ์ผ๋ก ๊ณ ์ ํ๋ฉด ์คํ์ผ์ด ์๋ง์ธ ๊ฒ์ ๋ณผ ์ ์์ต๋๋คใ
๊ตฌ์ฑ ์์ ๋ํผ๋ฅผ ์ฌ์ฉํ์ฌ ์ํํ์ง๋ง ๋ค์ ์ด์ํฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
export default class extends PureComponent {
constructor(props) {
super(props);
this.state = {
localData: props.data,
};
this.tableRef = React.createRef();
}
handleTableUpdate = () => {
this.setState({ localData: this.tableRef.current.getLocalData() });
}
render() {
return (
<Table
ref={this.tableRef}
columns={this.props.columns}
dataSource={this.props.data}
onChange={this.handleTableUpdate}
components={{
body: {
wrapper: (props) => (
<BodyWithSummary
columns={this.props.columns}
data={this.state.localData}
{...props}
/>
),
},
}}
/>
);
}
}
function BodyWithSummary(props) {
const { data, columns, ...otherProps } = props;
return (
<tbody {...otherProps}>
<React.Fragment>
{data && data.length > 0 && (
<tr>
{props.columns.map((col) => renderColumn(col, data))}
</tr>
)}
{props.children}
</React.Fragment>
</tbody>
);
}
์ฑ๊ฐ์ ์ ์ ํํฐ๋ง ๋ ํ์์ ์ง๊ณ ๋ฐ์ดํฐ๋ฅผ ๊ณ์ฐํ๋ ค๋ฉด getLocalData
๋ฅผ ํธ์ถํด์ผํ๋ค๋ ๊ฒ์
๋๋ค.
๋ณธ๋ฌธ ๋ํผ๊ฐ ํ
์ด๋ธ ์ฐธ์กฐ๋ฅผ ์ํ์ผ๋ก ๋ฐ๊ฑฐ๋ ๋ ๋๋ง ๋ ๋ฐ์ดํฐ์ ๋ ์ฝ๊ฒ ์ก์ธ์ค ํ ์์๋ ๊ฒฝ์ฐ ํจ์ฌ ๋ ์ข์ ๊ฒ์
๋๋ค (props.children์ ๋ฐ์ ๋
ธ๋ ๋ชฉ๋ก์ด๋ฉฐ ์ง๊ณ ๊ณ์ฐ์ ๊ทธ๋ค์ง ์ ์ฉํ์ง ์์).
footer
prop์ ์ฌ์ฉํ์ง๋ง ์ถ๊ฐ div ๋์ ํ
์ด๋ธ์์ ๋ ๋๋ง ํ ์ ์์ต๋๊น?
์ผ์์ ์ผ๋ก ๋ค์๊ณผ ๊ฐ์ด ์ฒ๋ฆฌ๋ฉ๋๋ค.
.ant-table-footer {
padding: 0;
}
footer={(currentPageData)=>{
return (
<Row style={{marginRight:17}}>
<Col span={4} className="brd">
<Card bordered={false} className="bgfb" bodyStyle={{padding:'10px 15px'}}>ๅ่ฎก</Card>
</Col>
<Col span={4} className="brd">
<Card bordered={false} className="bgfb" bodyStyle={{padding:'10px 15px'}}>123456789</Card>
</Col>
<Col span={4} className="brd">
<Card bordered={false} className="bgfb" bodyStyle={{padding:'10px 15px'}}>123456789</Card>
</Col>
<Col span={4} className="brd">
<Card bordered={false} className="bgfb" bodyStyle={{padding:'10px 15px'}}>123456789</Card>
</Col>
<Col span={4} className="brd">
<Card bordered={false} className="bgfb" bodyStyle={{padding:'10px 15px'}}>123456789</Card>
</Col>
<Col span={4}>
<Card bordered={false} className="bgfb" bodyStyle={{padding:'10px 15px'}}>123456789</Card>
</Col>
</Row>
);
}}
์๋ฒฝํ์ง ์์ต๋๋ค.
๊ณง ๋์ฌ ๊ธฐ๋ฅ ๋ฐ๋ฐ๋ฅ์ ๊ธฐ๋ O (โฉ_โฉ) O
@ybning ๊ณ ์ ์ปฌ๋ผ์ ๋ฌธ์ ๊ฐ ์์ต๋๊น? ์ด๋ฌํ ๊ณ ์ ๋ ์ด ์ค ์๋น์๊ฐ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. .
@yesmeck ๊ทํ์ ์์ ๋ ๋ด๋ถ ํ
์ด๋ธ ๊ณ์ฐ์ ์ค๋จํฉ๋๋ค : https://codesandbox.io/s/rrpo02qwkq
2 ํ์ด์ง๋ก ์ด๋ ํ ๋ค์ 1 ํ์ด์ง๋ก ๋์ ๊ฐ๋ฉด ๊ฐ ํ์์ ๋ฐ์ดํฐ๊ฐ ๋ณต์ ๋ฉ๋๋ค.
์ด ๋ฌธ์ ์ ๋ํ ์ ๋ฐ์ดํธ๊ฐ ์์ต๋๊น?
@linrf ์๋,
์ด๋ ๊ฒ.
https://codepen.io/chaegumi/pen/OaqxVd
๊ฑฐ๋ ์ง๊ณ ํต๊ณ์ total
prop์ ์ถ๊ฐ ํ ์ ์์ต๋๊น?
total
๋ footer
์ ๋ค๋ฆ
๋๋ค.
์ด ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํ๋ ํจ์ ๋ง ํ์ฉํฉ๋๋ค. ๊ธฐ๋ณธ๊ฐ์ reduce
๋ง์นจ๋ด ์ด์ ํฉ๊ณ๋ฅผ ๋ฃ์์ต๋๋ค.
antd์ ํ ์ด๋ธ ๋ฐ๋ฅ ๊ธ ๋ด์ฉ์ ๋ ๋๋ง์ ํนํ ํ ์ด๋ธ ์์ฒด์ ๊ณ ์ ๋ ์ด์ด์๋ ๊ฒฝ์ฐ ์ฌ์ฉํ๊ธฐ๊ฐ ์ฝ์ง ์์ต๋๋ค.
๋ ๊ฐ์ ํ ์ด๋ธ๋ก ๊ตฌํํ๋ ๋ฐฉ๋ฒ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. ํ๋๋ ์๋ณธ ํ ์ด๋ธ์ ๋ ๋๋งํ๊ณ ๋ค๋ฅธ ํ๋๋ ํ๋จ์ ๋ฐ๋ฅ ๊ธ ์์๋ฅผ ๋ ๋๋งํ๋ ๊ฒ์ ๋๋ค. ์คํ์ผ ๋ฒ์๋ฅผ ์ฌ์ฉํ์ฌ ํ ์ด๋ธ ๋ฐ๋ฅ ๊ธ์ ๊ด๊ณ ์ ์๋ ํ ์ด๋ธ ์คํฌ๋กค ์์ญ์ ์คํฌ๋กค ๋ง๋๋ฅผ ์จ ๊น๋๋ค. ๋ง์ง๋ง์ผ๋ก ๋ ํ ์ด๋ธ์ ๊ฐ๋ก ์คํฌ๋กค ์์น๋ฅผ ์ ๋ ฌํ๋ JS ์ฝ๋๋ฅผ ์ถ๊ฐํฉ๋๋ค. ๊ฑฐ์ ๋์ผํฉ๋๋ค.
๊ตฌ์ฑํ :
import React, { PureComponent } from 'react';
import { Table } from 'antd';
import styles from './index.less';
export default class ChartTable extends PureComponent {
constructor(props) {
super(props);
this.refBox = React.createRef();
}
componentDidMount() {
const tableList = Array.from(this.refBox.current.querySelectorAll('.ant-table-body'));
this.tableList = tableList;
tableList.forEach((table) => {
table.addEventListener('scroll', this.handleTableScroll);
});
}
componentWillUnmount() {
this.tableList.forEach((table) => {
table.removeEventListener('scroll', this.handleTableScroll);
});
}
handleTableScroll = (e) => {
const current = e.currentTarget;
this.tableList.forEach((table) => {
if (table !== current && table.scrollLeft !== current.scrollLeft) {
table.scrollLeft = current.scrollLeft;
}
});
}
renderFooterTable = () => {
const { columns, dataSource } = this.props;
const dataList = [{
department: 'ๅ่ฎก',
}];
return (
<Table
className={styles.footerTable}
pagination={false}
scroll={{ x: 'max-content' }}
size="small"
columns={columns}
dataSource={dataList}
/>
);
}
render() {
return (
<div ref={this.refBox}>
<Table
className={styles.mainTable}
pagination={false}
scroll={{ x: 'max-content', y: 350 }}
size="small"
columns={this.props.columns}
dataSource={this.props.dataSource}
/>
{this.renderFooterTable()}
</div>
);
}
}
์คํ์ผ ์ปค๋ฒ๋ฆฌ์ง ํ์ผ :
mainTable {
:global {
.ant-table-body::-webkit-scrollbar {
display: none;
}
}
}
.footerTable {
border-top: 1px solid #e8e8e8;
:global {
thead {
display: none;
}
}
}
+1 ๋ฐ๋ฅ ๊ธ์ ์ด ์ง๊ณ๋ฅผ ํ์ํ๋ ๋ฐฉ๋ฒ์ ์ํฉ๋๋ค.
component prop์ ์ฌ์ฉํ์ฌ ๊ตฌํํ ์ ์์ต๋๋ค.
const __Table = (totalsRow = initTotals(), key='tableKey') => ({
className,
style,
children
}) => (
<table className={className} style={style} key={key}>
{children}
<tfoot>
<tr>
// add tfoot td here
</tr>
</tfoot>
</table>
);
const TableWithTFoot = ({allData, columns}) =>
<Table
dataSource={allData.data}
columns={columns}
pagination={false}
components={{ table: __Table(allData.totals) }}
/>
@rororofff ๋์ด ๋ฌธ์ ์ $ 5.00๋ฅผ ํฌ์ํ์ต๋๋ค.
@piuccio ๋น์ ์ ์๊ฐ์ ๋ฐ๋ฅด๋ฉด, ๋๋ ๊ทธ๊ฒ์ ํ์ดํ ์คํฌ๋ฆฝํธ๋ก ์๋๋ค.
https://github.com/Arweil/antd-ext/blob/master/src/TableExt/TableExt.tsx
https://github.com/ant-design/ant-design/issues/5710#issuecomment -450855438
this.refBox = React.createRef();
์ด ๋ฒ์ ํจํค์ง๋ฅผ ์ฌ์ฉํ๊ณ ์ด ์ฝ๋๋ฅผ ์คํํ๋ฉด ์คํจํ์ต๋๋ค.
"antd": "2.13.14", "react": "15.4.0", "react-dom": "15.4.0"
์๋ฌ ๋ฉ์์ง
Uncaught TypeError: _react2.default.createRef is not a function
at new EstimationReport (psReport.js?18c1:47)
at eval (ReactCompositeComponent.js?063f:295)
at measureLifeCyclePerf (ReactCompositeComponent.js?063f:75)
at
@carvendy react
๊ฐ์ ธ์ฌ ๋ ์๋ง๋ ๋ชจ๋ ํด๊ฒฐ ์ค์ ์ผ ๊ฒ์
๋๋ค. ๋ณ๊ฒฝ ์๋
import from 'react';
์ด๊ฒ์ผ๋ก :
import * as react from 'react'
๊ตฌ์ฑ ์์๋ฅผ ๋ง๋ค์์ต๋๋ค.
์ด ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ๋ฐ๋ฅ ๊ธ ๋ ๋๋ง
๊ทธ๋ฌ๋ ํ์ฌ ์คํฌ๋กค ๋ง๋๋ ์ง์๋์ง ์์ต๋๋ค.
import React from 'react';
class TableFooter extends React.Component {
render() {
const { dataSource, columns } = this.props;
return (
<table className="ant-table">
<colgroup>
{columns.map((colModel, index) => {
return <col style={{
width: colModel.width,
minWidth: colModel.width
}} key={index} />
})}
</colgroup>
<tfoot >
<tr >
{columns.map((colum, idxCol) => {
return <td style={{ padding: "0px 8px" }} className={colum.className} key={idxCol}>
<strong>
{colum.footerContent ? colum.footerContent : (colum.footerSum ? dataSource.reduce((sum, record) => sum + parseFloat(record[colum.key]), 0) : "")}
</strong>
</td>
})}
</tr>
</tfoot>
</table>
)
}
}
export default TableFooter;
ํ์ด์ง ํธ์ถ
...
render() {
const columns = [
{
key: 'productName'
footerContent: 'SUM:',
},
{
key: 'quantity',
footerSum: true,
}
}
];
return (
<Table
columns={columns}
dataSource={dataSource}
footer={()=> {
return (
<TableFooter dataSource={dataSource} columns={columns} />
)
}
}
/>
)
....
var data = this.getLocalData ();
var current;
var pageSize;
var state = this.state; // ํ์ด์ง์ด ์์ผ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ๋ชจ๋ ํ์๋ฉ๋๋ค.
if (!this.hasPagination()) {
pageSize = Number.MAX_VALUE;
current = 1;
} else {
pageSize = state.pagination.pageSize;
current = this.getMaxCurrent(state.pagination.total || data.length);
} // ๅ้กต
// ---
// ๅฝๆฐๆฎ้ๅฐไบ็ญไบๆฏ้กตๆฐ้ๆถ๏ผ็ดๆฅ่ฎพ็ฝฎๆฐๆฎ
// ๅฆๅ่ฟ่ก่ฏปๅๅ้กตๆฐๆฎ
if (data.length > pageSize || pageSize === Number.MAX_VALUE) {
data = data.filter(function (_, i) {
return i >= (current - 1) * pageSize && i < current * pageSize;
});
}
return data;
}
์ด๊ฒ์ ํ ์ด๋ธ ์ฒ๋ฆฌ ๋ฐ์ดํฐ์ ์์ค ์ฝ๋๊ฐ ์ฌ๊ธฐ์ ๋ชฉ๋ก ๊ฐ์ ํฉ๊ณ๋ฅผ ๊ณ์ฐํ๊ณ ์ถ๋ ฅ ํ ๋ ์ด ๋ฐ์ดํฐ ์๋ฅผ ๋ํ๊ณ ํ์ด์ง ๋ฐ ํ์ด์ง ํฌ๊ธฐ์์ ๋ฐฉ๊ธ ์ถ๊ฐ ํ ๋ฐ์ดํฐ๋ฅผ ๋นผ๋ ํจ์๋ฅผ ์ถ๊ฐ ํ ์ ์๋์ง ์ฌ๋ถ์ ๋๋ค. @sorrycc
2 ๋ ํ์๋์ด ๋ฌธ์ ๋ ์ฌ์ ํ ์ฌ๋ผ์ง๋๋ค.
2 ๋ ํ์๋์ด ๋ฌธ์ ๋ ์ฌ์ ํ ์กด์ฌํฉ๋๋ค.
์๋ col์ ๋ค์ ์์ฑํ๊ณ ๋น ํ์ด์ง ํ ์ด๋ธ์ ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ๋ ๋ ๋๋ง์ ์์ ํ๋ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ์ต๋๋ค.
์ฌ๋ฌ ๋ฐ์ดํฐ๋ฅผ ์ ๋ก๋ํ์ง๋ง ๋งค๊น์ ๊ฒฝ์ฐ, ๊ทธ๊ฒ์ ์ดํด๋ฉ๋๋ค. https://github.com/ant-design/ant-design/blob/fee5e291632cce131611dd1a9e2ab89e02ee43a3/components/table/Table.tsx#L407
ํ๋ณดํ๊ณ ์ถ์ง๋ง API ๋์์ธ์ด ์์ฌ์ @ afc163 ์๊ตฌ ์ฌํญ์ ์ถฉ์กฑํ์ง ๋ชปํ๋ ๊ฒ์ด
2 ๋ ํ์๋์ด ๋ฌธ์ ๋ ์ฌ์ ํ ์กด์ฌํฉ๋๋ค.
๊ฐ๋ ๊ธธ์ ์ ํ ์ด๋ธ. ์ ํ ์ด๋ธ์ ๊ธฐ๋ํฉ๋๋ค.
https://github.com/ant-design/ant-design/issues/16911#issuecomment -523423460
@ alexchen1875 ์ด๊ฒ๊ณผ ๊ด๋ จ๋ ์ด๋ค ๊ฒ๋ ์ธ๊ธํ์ง ์์์ต๋๋ค.
@ alexchen1875 ์ด๊ฒ๊ณผ ๊ด๋ จ๋ ์ด๋ค ๊ฒ๋ ์ธ๊ธํ์ง ์์์ต๋๋ค.
ํ ์น์ ์ ์ง์นจ์์ฃผ์ ๊น๊ฒ ์ฝ์ผ์ญ์์ค.
ํธ์ ๋ด์ ๊ฐ๊ธฐ
PR์ ์ ์ถํ๊ณ ๊ฑด๋ ๋ฐ๊ธฐ๋ฅผ ์ง์ํ๊ธฐ ์ํด ์ผ์์ ์ผ๋ก "๋ฐ์ดํฐ๋ฅผ ์๋ฅด์ง ์๋๋ก ๋ฐ์ดํฐ ํ์ฉ"์ํ์ ์ถ๊ฐํ๊ณ ์ถ์ต๋๋ค. https://github.com/ant-design/ant-design/blob/61e319b66826530a1882c20a41862a15d57b120a/components/table/Table.tsx # L408 ์ ํํฐ ๋ก์ง์ ํ์ด์ง ๋งค๊น์ ๊ฒฝ์ฐ https://github.com/ant-design/ant-design/issues/5710#issuecomment -524164125๋ ์ฌ์ฉํ ์ ์๋๋กํฉ๋๋ค. ํ์ด ์๋ฝํ ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค .. .
์ด ๋ฐ๋ชจ๋ฅผ ์์
๊ณ ์ ์ด , ํค๋ ๊ทธ๋ฃน , ์
๋ณํฉ ๋ฐ ์คํฌ๋กค ์ง์ ์ถ๊ฐ,
๋๋ ์ฌ์ฉํ๋ค
์ฌ์ฉ๋ฒ :
const calcRow = [
{
colspan: 2,
render: () => 'total'
},
{
render: sum => sum('age')
},
{
render: sum => sum('score')
}
]
antd v4๋ Table summary
: https://github.com/ant-design/ant-design/issues/21656
https://ant.design/components/table/#components -table-demo-summary
antd v4๋ ํ ์ด๋ธ
summary
: # 21656์ ์ง์ํ์ต๋๋ค.https://ant.design/components/table/#components -table-demo-summary
antd4๋ ์์ฝ์ ์ง์ํ์ง๋ง์ด ์์ฝ์ ์ฌ์ ํ โโ๋ฐ๋ณต๋์ด์ผํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ํ์ฌ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ฌด๋ฃ์ด์ง๋ง ๋์์ ์ฝ๋๊ฐ ๋๋ฌด ๋ฒ๊ฑฐ๋กญ๊ณ ์๋ ์๋์ ์ผ์นํ์ง ์๋๋ค๋ ๊ฒ์ ๋๋ค. antd4๊ฐ ์ ์ ๋ ๋จ์ ํด์ง๋๋ค.
์ผ๋ฐ์ ์ธ ๊ฐ๋จํ ์๋๋ฆฌ์ค๋ ํ์ฌ ํ์ด์ง์ ๋ฐ์ดํฐ๋ฅผ ์์ฝํ๋ ๊ฒ์ ๋๋ค. ์น์ํ ๊ฒฝํ์ ์์ฝ ์ ์ง์ ๊ตฌ์ฑํ๋ ๊ฒ์ด์ด์ผํฉ๋๋ค. ์ฆ, cloumn์์
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
footer
ํ ์ด๋ธ์ ๋ง๊ฒ ๋ญ๊ฐ๋ฅผ ํ ์ ์์๊น์?