Skip to content

Commit

Permalink
deps: upgrade rc-table (ant-design#2958)
Browse files Browse the repository at this point in the history
* feat: remove Table columns paging, close: ant-design#2883

* css: add style for table multi-header

* feat: multi-header supports fitler & sorter and so on

* feat: multi-heaader works with Table[scroll.y]

* feat: multi-header should works with Table[scroll.x]

* style: update code style to please lint
  • Loading branch information
benjycui authored and afc163 committed Sep 9, 2016
1 parent 4026221 commit 77a45f0
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 54 deletions.
8 changes: 4 additions & 4 deletions components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Pagination from '../pagination';
import Icon from '../icon';
import Spin from '../spin';
import classNames from 'classnames';
import { flatArray } from './util';
import { flatArray, treeMap } from './util';
import assign from 'object-assign';
import splitObject from '../_util/splitObject';

Expand Down Expand Up @@ -280,7 +280,7 @@ export default class Table extends React.Component<TableProps, any> {
}

getFilteredValueColumns(columns?) {
return (columns || this.props.columns || []).filter(column => 'filteredValue' in column);
return (columns || this.props.columns || []).filter(column => column.filteredValue);
}

getFiltersFromColumns(columns?) {
Expand Down Expand Up @@ -373,7 +373,7 @@ export default class Table extends React.Component<TableProps, any> {
const newState = {
selectionDirty: false,
pagination,
filters: null,
filters: {},
};
const filtersToSetState = assign({}, filters);
// Remove filters which is controlled
Expand Down Expand Up @@ -631,7 +631,7 @@ export default class Table extends React.Component<TableProps, any> {
renderColumnsDropdown(columns) {
const { sortOrder } = this.state;
const locale = this.getLocale();
return columns.map((originColumn, i) => {
return treeMap(columns, (originColumn, i) => {
let column = assign({}, originColumn);
let key = this.getColumnKey(column, i);
let filterDropdown;
Expand Down
125 changes: 125 additions & 0 deletions components/table/demo/grouping-columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
order: 20
title:
en-US: Grouping table head
zh-CN: 表头分组
---

## zh-CN

`columns[n]` 可以内嵌 `children`,以渲染分组表头。

## en-US

Group table head with `columns[n].children`

```jsx
import { Table } from 'antd';

const columns = [
{
title: '姓名',
dataIndex: 'name',
key: 'name',
width: 100,
fixed: 'left',
filters: [{
text: '姓李的',
value: '',
}, {
text: '姓胡的',
value: '',
}],
onFilter: (value, record) => record.name.indexOf(value) === 0,
},
{
title: '其它',
children: [
{
title: '年龄',
dataIndex: 'age',
key: 'age',
width: 100,
sorter: (a, b) => a.age - b.age,
},
{
title: '住址',
children: [
{
title: '街道',
dataIndex: 'street',
key: 'street',
width: 200,
},
{
title: '小区',
children: [
{
title: '单元',
dataIndex: 'building',
key: 'building',
width: 50,
},
{
title: '门牌',
dataIndex: 'number',
key: 'number',
width: 100,
},
],
},
],
},
],
},
{
title: '公司',
children: [
{
title: '地址',
dataIndex: 'companyAddress',
key: 'companyAddress',
width: 200,
},
{
title: '名称',
dataIndex: 'companyName',
key: 'companyName',
width: 200,
},
],
},
{
title: '性别',
dataIndex: 'gender',
key: 'gender',
width: 60,
fixed: 'right',
},
];

const data = [];
for (let i = 0; i < 100; i++) {
data.push({
key: i,
name: '胡彦祖',
age: Math.ceil(Math.random() * 100),
street: '拱墅区和睦街道',
building: 3,
number: 2035,
companyAddress: '西湖区湖底公园',
companyName: '湖底有限公司',
gender: '',
});
}

ReactDOM.render(
<Table
columns={columns}
dataSource={data}
bordered size="middle"
scroll={{ x: 1010, y: 240 }}
/>,
mountNode
);
```
49 changes: 0 additions & 49 deletions components/table/demo/paging-columns.md

This file was deleted.

3 changes: 3 additions & 0 deletions components/table/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@
.@{table-prefix-cls}-thead > tr > th,
.@{table-prefix-cls}-tbody > tr > td {
border-right: 1px solid @border-color-split;
}
.@{table-prefix-cls}-thead > tr:first-child > th,
.@{table-prefix-cls}-tbody > tr > td {
&:last-child {
border-right: 0;
}
Expand Down
10 changes: 10 additions & 0 deletions components/table/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ export function flatArray(data = [], childrenName = 'children') {
loop(data);
return result;
}

export function treeMap(tree: Object[], mapper: Function, childrenName = 'children') {
return tree.map((node, index) => {
const extra = {};
if (node[childrenName]) {
extra[childrenName] = treeMap(node[childrenName], mapper, childrenName);
}
return assign({}, mapper(node, index), extra);
});
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"rc-slider": "~4.0.0",
"rc-steps": "~2.1.5",
"rc-switch": "~1.4.2",
"rc-table": "~4.6.0",
"rc-table": "~5.0.0",
"rc-tabs": "~5.9.2",
"rc-time-picker": "^2.0.0",
"rc-tooltip": "~3.4.2",
Expand Down

0 comments on commit 77a45f0

Please sign in to comment.