Skip to content

Commit

Permalink
Table componentDidUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
docoder committed Jan 9, 2020
1 parent 24ca852 commit b009836
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
15 changes: 11 additions & 4 deletions example/src/containers/BaseTable/index.js
Expand Up @@ -3,7 +3,7 @@
* @Email: docoder@163.com
*/
import React from 'react';
import { Table } from 'ant-colony-ui';
import { Table, Button } from 'ant-colony-ui';
import styled from 'styled-components';

const DATASOURCE = [
Expand Down Expand Up @@ -155,7 +155,8 @@ const TableBody = styled.div`
const StyledTable = styled(Table)`
margin-top: 20px;
`;

const StyledButton = styled(Button)`
`;
export default class BaseTable extends React.Component {
state = {
pagination: {
Expand All @@ -167,13 +168,19 @@ export default class BaseTable extends React.Component {
},
data: {
test: 'test'
}
},
columns: TABLE_COLUMNS,
}
render() {
return (
<TableBody>
<StyledButton title="Change Columns" onClick={() => {
let newColumns = [...this.state.columns]
newColumns.pop()
this.setState({columns: newColumns})
}} />
<StyledTable
columns={TABLE_COLUMNS}
columns={this.state.columns}
dataSource={DATASOURCE}
pagination={this.state.pagination}
onChange={(pagination, filters, sorter) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ant-colony-ui",
"version": "1.7.17",
"version": "1.7.18",
"description": "Ant Colony UI Toolkit based on Ant Design and React",
"author": "docoder",
"license": "MIT",
Expand Down
6 changes: 6 additions & 0 deletions src/components/UI/Table/index.js
Expand Up @@ -162,6 +162,12 @@ export default class Table extends React.Component {
}
this.props.onChange(pagination, filters, sorter);
}
componentDidUpdate(prevProps) {
if (prevProps.columns !== this.props.columns) {
this.columns = this.props.columns
this.setState({newColumns: this.columns})
}
}
render() {
const {
rowKey,
Expand Down

0 comments on commit b009836

Please sign in to comment.