/* eslint-disable no-console,func-names,react/no-multi-comp */
const React = require('react');
const ReactDOM = require('react-dom');
const Table = require('rc-table');
require('rc-table/assets/index.less');

const CheckBox = React.createClass({
  render() {
    const props = this.props;
    return (
      <label>
        <input type="checkbox" />
        {props.id}
      </label>
    );
  },
});

const MyTable = React.createClass({
  getInitialState() {
    const props = this.props;
    return {
      data: props.data,
      expandedRowKeys: [],
    };
  },

  onExpand(expanded, record) {
    console.log('onExpand', expanded, record);
  },

  onExpandedRowsChange(rows) {
    this.setState({
      expandedRowKeys: rows,
    });
  },

  toggleButton() {
    if (this.state.expandedRowKeys.length) {
      const closeAll = () => this.setState({ expandedRowKeys: [] });
      return <button onClick={closeAll}>关闭所有</button>;
    }
    const openAll = () => this.setState({ expandedRowKeys: [0, 1, 2] });
    return <button onClick={openAll}>展开全部</button>;
  },

  handleClick(index) {
    const self = this;
    return () => {
      self.remove(index);
    };
  },

  remove(index) {
    const rows = this.state.data;
    rows.splice(index, 1);
    this.setState({
      data: rows,
    });
  },

  checkbox(a) {
    return <CheckBox id={a} />;
  },

  expandedRowRender(record) {
    console.log(record);
    return <p>extra: {record.a}</p>;
  },

  renderAction(o, row, index) {
    return <a href="#" onClick={this.handleClick(index)}>删除</a>;
  },

  render() {
    const state = this.state;
    const columns = [
      { title: '表头1', dataIndex: 'a', key: 'a', width: 100, render: this.checkbox },
      { title: '表头2', dataIndex: 'b', key: 'b', width: 100 },
      { title: '表头3', dataIndex: 'c', key: 'c', width: 200 },
      { title: '操作', dataIndex: '', key: 'x', render: this.renderAction },
    ];
    return (
      <div>
        {this.toggleButton()}
        <Table
          columns={columns}
          expandIconAsCell
          expandedRowRender={this.expandedRowRender}
          expandedRowKeys={this.state.expandedRowKeys}
          onExpandedRowsChange={this.onExpandedRowsChange}
          onExpand={this.onExpand}
          data={state.data}
        />
      </div>
    );
  },
});

const data = [
  { key: 0, a: '123' },
  { key: 1, a: 'cdd', b: 'edd' },
  { key: 2, a: '1333', c: 'eee', d: 2 },
];

ReactDOM.render(
  <div>
    <h2>expandedRowRender</h2>
    <MyTable
      data={data}
      className="table"
    />
  </div>,
  document.getElementById('__react-content')
);

@@ -206,200 +206,8 @@
 );%0A%0A
-const CheckBox = React.createClass(%7B%0A  render() %7B%0A    const props = this.props;%0A    return (%0A      %3Clabel%3E%0A        %3Cinput type=%22checkbox%22 /%3E%0A        %7Bprops.id%7D%0A      %3C/label%3E%0A    );%0A  %7D,%0A%7D);%0A%0A
 cons
@@ -722,12 +722,17 @@
 ll%7D%3E
-%E5%85%B3%E9%97%AD%E6%89%80%E6%9C%89
+Close All
 %3C/bu
@@ -858,12 +858,18 @@
 ll%7D%3E
-%E5%B1%95%E5%BC%80%E5%85%A8%E9%83%A8
+Expand All
 %3C/bu
@@ -885,112 +885,8 @@
 %7D,%0A%0A
-  handleClick(index) %7B%0A    const self = this;%0A    return () =%3E %7B%0A      self.remove(index);%0A    %7D;%0A  %7D,%0A%0A
   re
@@ -909,20 +909,20 @@
   const 
-rows
+data
  = this.
@@ -937,20 +937,20 @@
 ta;%0A    
-rows
+data
 .splice(
@@ -983,87 +983,16 @@
 te(%7B
-%0A      data: rows,%0A    %7D);%0A  %7D,%0A%0A  checkbox(a) %7B%0A    return %3CCheckBox id=%7Ba%7D /%3E
+ data %7D)
 ;%0A  
@@ -1161,24 +1161,25 @@
 ck=%7B
-this.handleClick
+() =%3E this.remove
 (ind
@@ -1187,10 +1187,14 @@
 x)%7D%3E
-%E5%88%A0%E9%99%A4
+Delete
 %3C/a%3E
@@ -1282,18 +1282,22 @@
 title: '
-%E8%A1%A8%E5%A4%B4
+title 
 1', data
@@ -1332,31 +1332,8 @@
  100
-, render: this.checkbox
  %7D,%0A
@@ -1348,18 +1348,22 @@
 title: '
-%E8%A1%A8%E5%A4%B4
+title 
 2', data
@@ -1418,10 +1418,14 @@
 e: '
-%E8%A1%A8%E5%A4%B4
+title 
 3', 
@@ -1484,10 +1484,17 @@
 e: '
-%E6%93%8D%E4%BD%9C
+Operation
 ', d
@@ -1678,16 +1678,43 @@
 nAsCell%0A
+          expandRowByClick%0A
         

update example code style