context.jsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React from 'react';
  2. import { Table, Button } from '../../../../index';
  3. class App extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. count: 1,
  8. };
  9. this.columns = [
  10. {
  11. title: 'Name',
  12. dataIndex: 'name',
  13. render: (text, record, index) => {
  14. console.log(text, record, index);
  15. return <a>{text}</a>;
  16. },
  17. },
  18. {
  19. title: 'Age',
  20. dataIndex: 'age',
  21. },
  22. {
  23. title: 'Address',
  24. dataIndex: 'address',
  25. },
  26. ];
  27. this.data = [
  28. {
  29. key: '1',
  30. name: 'John Brown',
  31. age: 32,
  32. address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
  33. },
  34. {
  35. key: '2',
  36. name: 'Jim Green',
  37. age: 42,
  38. address: 'London No. 1 Lake Park',
  39. },
  40. {
  41. key: '3',
  42. name: 'Joe Black',
  43. age: 32,
  44. address: 'Sidney No. 1 Lake Park',
  45. },
  46. {
  47. key: '4',
  48. name: 'Michael James',
  49. age: 99,
  50. address: 'Sidney No. 1 Lake Park',
  51. },
  52. ];
  53. }
  54. render() {
  55. const { count } = this.state;
  56. return (
  57. <>
  58. <div>{`count: ${count}`}</div>
  59. <Table columns={this.columns} dataSource={this.data} pagination={false} />
  60. <Button onClick={() => {
  61. this.setState({ count: count + 1 });
  62. }}>
  63. Click
  64. </Button>
  65. </>
  66. );
  67. }
  68. }
  69. export default App;