디자인이라고는 모르는 BE 개발자가 react로 어드민 개발하는 방법
=> 라이브러리를 열심히 활용하기 ^^...
라이브러리를 선택한 기준은 다음과 같다.
구글링을 해보았을때 1위는 Meterial UI, 2위는 Ant Design이라고 하여 둘 중에 고민하였으나 Ant Design의 심플함이 마음에 들어 선택.
알리바바 그룹에서 만들어서 (=중국꺼...) 아주 가끔 예시페이지에 갑분 중국어가 튀어나올 때가 있었지만 가이드가 영어로 제공되어 개발하는데 어려움은 없었다.
⬇️ Meterial UI - table
⬇️ Ant Design - table
ref: https://ant.design/components/table
테이블에 나타낼 데이터를 dataSource에 넣고, 해당 데이터의 속성(attribute)를 columns에 넣는다. (초단순)
const dataSource = [
{
key: '1',
name: 'Mike',
age: 32,
address: '10 Downing Street',
},
{
key: '2',
name: 'John',
age: 42,
address: '10 Downing Street',
},
];
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
},
{
title: 'Age',
dataIndex: 'age',
key: 'age',
},
{
title: 'Address',
dataIndex: 'address',
key: 'address',
},
];
<Table dataSource={dataSource} columns={columns} />;
['ascend' | 'descend']
const columns = [
{
title: 'Name',
dataIndex: 'name',
sorter: (a, b) => a.name.length - b.name.length,
sortDirections: ['descend'],
},
{
title: 'Age',
dataIndex: 'age',
defaultSortOrder: 'descend',
sorter: (a, b) => a.age - b.age,
},
{
title: 'Address',
dataIndex: 'address'
},
];
[{text:"보여지는 값", value:"필터링하는 값"}]
const columns = [
{
title: 'Name',
dataIndex: 'name',
filters: [
{
text: 'Joe',
value: 'Joe',
},
{
text: 'Jim',
value: 'Jim',
},
{
text: 'Submenu',
value: 'Submenu',
children: [
{
text: 'Green',
value: 'Green',
},
{
text: 'Black',
value: 'Black',
},
],
},
],
// specify the condition of filtering result
// here is that finding the name started with `value`
onFilter: (value, record) => record.name.indexOf(value) === 0,
sorter: (a, b) => a.name.length - b.name.length,
sortDirections: ['descend'],
},
{
title: 'Age',
dataIndex: 'age',
defaultSortOrder: 'descend',
sorter: (a, b) => a.age - b.age,
},
{
title: 'Address',
dataIndex: 'address',
filters: [
{
text: 'London',
value: 'London',
},
{
text: 'New York',
value: 'New York',
},
],
onFilter: (value, record) => record.address.indexOf(value) === 0,
},
];
<Table
columns={columns}
dataSource={dataSource}
pagination={{
pageSize: 10,
position: ['topRight', 'bottomRight'],
hideOnSinglePage: true
}}
/>;
ref: https://ant.design/components/icon
다양한 아이콘을 outlined / Filled / Two Tone 세가지 테마로 제공한다. 아주 깔꼬롬하고 style로 색상만 지정해주면 내 마음대로 쓸 수 있다!