table.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-04-27 11:19:40
  4. * @LastEditTime: 2021-05-16 21:50:53
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /react-antd-admin-template/src/views/groupManage/groupIdentity/table.js
  8. */
  9. import React from 'react';
  10. import { Table,Popconfirm, Form} from 'antd';
  11. class EditableTable extends React.Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = { data:[], editingKey: '',loading:false};
  15. this.columns = [
  16. ...props.columns,
  17. {
  18. title: '操作',
  19. dataIndex: 'operation',
  20. render: (text, record) => {
  21. const { editingKey} = this.state;
  22. // console.log({editingKey,record});
  23. return (
  24. <span>
  25. <Popconfirm title=" 是否确定删除?" onConfirm={()=>this.delItem(record)}>
  26. <a disabled={editingKey !== ''} >
  27. 删除
  28. </a>
  29. </Popconfirm>
  30. </span>
  31. );
  32. },
  33. },
  34. ];
  35. }
  36. componentDidMount(){
  37. this.setState({
  38. data:this.props.data
  39. });
  40. }
  41. componentDidUpdate(prevProps, prevState){
  42. // console.log({prevProps, prevState});
  43. if(prevProps.ifUpdateList){
  44. console.log('update');
  45. this.setState({
  46. data:this.props.data
  47. });
  48. }
  49. }
  50. isEditing = record => {
  51. // console.log(record.id,this.state.editingKey);
  52. return record.id === this.state.editingKey;
  53. }
  54. editItem=(record)=>{
  55. this.props.callbackFromChild(record);
  56. }
  57. delItem=record=>{
  58. this.props.deleteCallback(record);
  59. }
  60. changePage(current){
  61. this.setState({ loading: true });
  62. this.props.paginationCallback({'currPage':current})
  63. }
  64. render() {
  65. const columns = this.columns.map(col => {
  66. if (!col.editable) {
  67. return col;
  68. }
  69. return {
  70. ...col,
  71. onCell: record => ({
  72. record,
  73. }),
  74. };
  75. });
  76. const {
  77. currPage,
  78. totalCount,
  79. } = this.props.pages;
  80. const paginationProps = {
  81. showSizeChanger: false,
  82. showQuickJumper: false,
  83. showTotal: () => `共${totalCount}条`,
  84. pageSize: 10,
  85. current: currPage,
  86. total: totalCount,
  87. onChange: (current) => this.changePage(current),
  88. }
  89. return (
  90. <Table
  91. bordered
  92. loading={this.state.loading}
  93. pagination={paginationProps}
  94. dataSource={this.state.data}
  95. columns={columns}
  96. rowClassName="editable-row"
  97. />
  98. );
  99. }
  100. }
  101. const EditableFormTable = Form.create()(EditableTable);
  102. export default EditableFormTable;