Skip to content

Commit

Permalink
Merge pull request alibaba-fusion#1915 from youluna/feat-table-column…
Browse files Browse the repository at this point in the history
…s-sticky

Feat table columns sticky
  • Loading branch information
youluna authored Aug 7, 2020
2 parents efd5da9 + 70af5e3 commit 4a9a79e
Show file tree
Hide file tree
Showing 24 changed files with 1,080 additions and 57 deletions.
85 changes: 85 additions & 0 deletions docs/table/demo/basic-columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 通过columns设置列

- order: 0

通过 `columns` 参数设置列

:::lang=en-us
# Simple

- order: 0

Set table columns via `columns`
:::

---

````jsx
import { Table } from '@alifd/next';

const dataSource = () => {
const result = [];
for (let i = 0; i < 5; i++) {
result.push({
title: {name: `Quotation for 1PCS Nano ${3 + i}.0 controller compatible`},
id: 100306660940 + i,
time: 2000 + i
});
}
return result;
};
const render = (value, index, record) => {
return <a href="javascript:;">Remove({record.id})</a>;
};

const columns = [{
title: "Title1",
dataIndex: "id",
width: 140,
}, {
title: "Group2-7",
children: [{
title: "Title2",
dataIndex: "id",
width: 140,
}, {
title: "Title3",
dataIndex: "title.name",
lock: true,
width: 200
}, {
title: 'Group4-7',
children: [{
title: "Title4",
dataIndex: "title.name",
width: 400,
}, {
title: "Title5",
dataIndex: "title.name",
width: 200
}, {
title: 'tet',
children: [{
title: "Title6",
dataIndex: "title.name",
width: 400,
}, {
title: "Title7",
dataIndex: "title.name",
width: 200
}]
}]
}]
}, {
title: '',
children: [{
title: "Time",
dataIndex: "time",
width: 500,
}, {
cell: render,
width: 200
}]
}];
ReactDOM.render(<Table columns={columns} dataSource={dataSource()} />, mountNode);
````
78 changes: 78 additions & 0 deletions docs/table/demo/expanded-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# 可展开-锁列

- order: 6

(IE下不支持) `Table.StickyLock` 模式下,展开行的可视区域宽度与 `Table` 占屏幕宽度保持一致, 本模式下 `expandedRowIndent``[0, 0]`,不可修改。

:::lang=en-us
# Expandable

- order: 6

(Can't work with IE)When you use `Table.StickyLock`, the width of expanded row will be the same as the width of table take in screen. `expandedRowIndent` will be `[0, 0]`, and it can't be modified.
:::

---

````jsx
import { Table, Button } from '@alifd/next';

const dataSource = () => {
const result = [];
for (let i = 0; i < 5; i++) {
result.push({
title: `Quotation for 1PCS Nano ${3 + i}.0 controller compatible`,
id: 100306660940 + i,
time: 2000 + i
});
}
return result;
},
expandedRowRender = (record, rowIndex) => {
if(rowIndex === 0) {
return record.title;
}
return (<Table.StickyLock hasBorder={false} dataSource={dataSource()}>
<Table.Column title="Id" dataIndex="id" lock width={100}/>
<Table.Column title="Title" dataIndex="title" width={200}/>
<Table.Column title="Time" dataIndex="time" width={200}/>
<Table.Column title="Title" dataIndex="title" width={200}/>
<Table.Column title="Title" dataIndex="title" width={200}/>
<Table.Column title="Title" dataIndex="title" width={200}/>
<Table.Column title="Title" dataIndex="title" width={200}/>
</Table.StickyLock>)
},
render = (value, index, record) => {
return <a>Remove({record.id})</a>;
};

class App extends React.Component {
constructor(props) {
super(props);
this.state = {
dataSource: dataSource()
};
}

render() {
return (<div>
<Table.StickyLock
expandedIndexSimulate
dataSource={this.state.dataSource}
hasBorder={false}
// expandedRowIndent 仅在IE下才会生效,非IE模式下为[0,0]且不可修改
expandedRowIndent={[2, 0]}
expandedRowRender={expandedRowRender}
onRowClick={() => console.log('rowClick')}
>
<Table.Column title="Id" dataIndex="id" lock width={100}/>
<Table.Column title="Title" dataIndex="title" width={200}/>
<Table.Column title="Time" dataIndex="time" width={200}/>
<Table.Column cell={render} width={300}/>
</Table.StickyLock>
</div>);
}
}

ReactDOM.render(<App/>, mountNode);
````
1 change: 1 addition & 0 deletions docs/table/index.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ ReactDOM.render(
| filterParams | currently filtered keys, use this property to control which menu in the table's header filtering options is selected, in the format {dataIndex: {selectedKeys:\[]}}<br> Example: <br> Suppose you want to control dataIndex as Select <br><Table filterParams={{id: {selectedKeys: ['one']}}}/> for the menu item whose key is one in the filtering menu of the id column. | Object | - |
| sort | the currently sorted field, use this property to control the sorting of the table's fields in the format {dataIndex: 'asc'} | Object | - |
| sortIcons | customize sortIcons, to set top and bottom layout e.g.`{desc: <Icon style={{top: '6px', left: '4px'}} type={'arrow-down'} size="small" />, asc: <Icon style={{top: '-6px', left: '4px'}} type={'arrow-up'} size="small" />}` | Object | - |
| columns | equals to Table.Column, but Table.Column has a higher priority | Array | - |
| emptyContent | content when the table is empty | ReactNode | - |
| primaryKey | the primary key of data in the dataSource, if the attribute in the given data source does not contain the primary key, it will cause selecting all | String | 'id' |
| expandedRowRender | rendering function for expanded row<br><br>**signatures**:<br>Function(record: Object, index: Number) => Element<br>**params**:<br>_record_: {Object} the record corresponding to the row<br>_index_: {Number} the index corresponding to the row<br>**returns**:<br>{Element} render content<br> | Function | - |
Expand Down
1 change: 1 addition & 0 deletions docs/table/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ ReactDOM.render(
| filterParams | 当前过滤的的keys,使用此属性可以控制表格的头部的过滤选项中哪个菜单被选中,格式为 {dataIndex: {selectedKeys:\[]}}<br>示例:<br>假设要控制dataIndex为id的列的过滤菜单中key为one的菜单项选中<br>`<Table filterParams={{id: {selectedKeys: ['one']}}}/>` | Object | - |
| sort | 当前排序的字段,使用此属性可以控制表格的字段的排序,格式为{dataIndex: 'asc'} | Object | - |
| sortIcons | 自定义排序按钮,例如上下排布的: `{desc: <Icon style={{top: '6px', left: '4px'}} type={'arrow-down'} size="small" />, asc: <Icon style={{top: '-6px', left: '4px'}} type={'arrow-up'} size="small" />}` | Object | - |
| columns | 等同于写子组件 Table.Column ,子组件优先级更高 | Array | - |
| emptyContent | 设置数据为空的时候的表格内容展现 | ReactNode | - |
| primaryKey | dataSource当中数据的主键,如果给定的数据源中的属性不包含该主键,会造成选择状态全部选中 | String | 'id' |
| expandedRowRender | 额外渲染行的渲染函数<br><br>**签名**:<br>Function(record: Object, index: Number) => Element<br>**参数**:<br>_record_: {Object} 该行所对应的数据<br>_index_: {Number} 该行所对应的序列<br>**返回值**:<br>{Element} 渲染内容<br> | Function | - |
Expand Down
23 changes: 21 additions & 2 deletions src/table/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class Table extends React.Component {
*/
locale: PropTypes.object,
components: PropTypes.object,
/**
* 等同于写子组件 Table.Column ,子组件优先级更高
*/
columns: PropTypes.array,
/**
* 设置数据为空的时候的表格内容展现
Expand Down Expand Up @@ -317,13 +320,20 @@ class Table extends React.Component {

static contextTypes = {
getTableInstance: PropTypes.func,
getTableInstanceForFixed: PropTypes.func,
getTableInstanceForVirtual: PropTypes.func,
};

constructor(props, context) {
super(props, context);
const { getTableInstance, getTableInstanceForVirtual } = this.context;
const {
getTableInstance,
getTableInstanceForVirtual,
getTableInstanceForFixed,
} = this.context;
getTableInstance && getTableInstance(props.lockType, this);
getTableInstanceForFixed &&
getTableInstanceForFixed(props.lockType, this);
getTableInstanceForVirtual &&
getTableInstanceForVirtual(props.lockType, this);
this.notRenderCellIndex = [];
Expand Down Expand Up @@ -352,6 +362,7 @@ class Table extends React.Component {

componentDidMount() {
this.notRenderCellIndex = [];
this.tableOuterWidth = this.tableEl && this.tableEl.clientWidth;
}

shouldComponentUpdate(nextProps, nextState, nextContext) {
Expand All @@ -368,6 +379,7 @@ class Table extends React.Component {

componentDidUpdate() {
this.notRenderCellIndex = [];
this.tableOuterWidth = this.tableEl && this.tableEl.clientWidth;
}

normalizeChildrenState(props) {
Expand Down Expand Up @@ -417,7 +429,7 @@ class Table extends React.Component {
let hasGroupHeader = false;
const flatChildren = [],
groupChildren = [],
getChildren = (propsChildren, level) => {
getChildren = (propsChildren = [], level) => {
groupChildren[level] = groupChildren[level] || [];
propsChildren.forEach(child => {
if (child.children) {
Expand Down Expand Up @@ -588,6 +600,7 @@ class Table extends React.Component {
cellRef={this.getCellRef}
onRowClick={onRowClick}
expandedIndexSimulate={expandedIndexSimulate}
tableOuterWidth={this.tableOuterWidth}
onRowMouseEnter={onRowMouseEnter}
onRowMouseLeave={onRowMouseLeave}
dataSource={dataSource}
Expand Down Expand Up @@ -728,6 +741,10 @@ class Table extends React.Component {
});
};

getTableEl = ref => {
this.tableEl = ref;
};

render() {
const ret = this.normalizeChildrenState(this.props);
this.groupChildren = ret.groupChildren;
Expand Down Expand Up @@ -769,6 +786,7 @@ class Table extends React.Component {
loadingComponent: LoadingComponent = Loading,
tableLayout,
tableWidth,
ref,
...others
} = this.props,
cls = classnames({
Expand All @@ -789,6 +807,7 @@ class Table extends React.Component {
<div
className={cls}
style={style}
ref={ref || this.getTableEl}
{...obj.pickOthers(Object.keys(Table.propTypes), others)}
>
{table}
Expand Down
Loading

0 comments on commit 4a9a79e

Please sign in to comment.