123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- /*
- * @Author: your name
- * @Date: 2021-04-27 11:19:40
- * @LastEditTime: 2021-05-16 21:50:53
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: /react-antd-admin-template/src/views/groupManage/groupIdentity/table.js
- */
- import React from 'react';
- import { Table,Popconfirm, Form} from 'antd';
- class EditableTable extends React.Component {
-
- constructor(props) {
- super(props);
- this.state = { data:[], editingKey: '',loading:false};
- this.columns = [
- ...props.columns,
- {
- title: '操作',
- dataIndex: 'operation',
- render: (text, record) => {
- const { editingKey} = this.state;
- // console.log({editingKey,record});
- return (
- <span>
-
- <Popconfirm title=" 是否确定删除?" onConfirm={()=>this.delItem(record)}>
- <a disabled={editingKey !== ''} >
- 删除
- </a>
- </Popconfirm>
- </span>
-
- );
- },
- },
- ];
- }
- componentDidMount(){
- this.setState({
- data:this.props.data
- });
-
- }
- componentDidUpdate(prevProps, prevState){
- // console.log({prevProps, prevState});
- if(prevProps.ifUpdateList){
- console.log('update');
- this.setState({
- data:this.props.data
- });
- }
- }
- isEditing = record => {
- // console.log(record.id,this.state.editingKey);
- return record.id === this.state.editingKey;
- }
-
- editItem=(record)=>{
- this.props.callbackFromChild(record);
- }
- delItem=record=>{
- this.props.deleteCallback(record);
- }
- changePage(current){
- this.setState({ loading: true });
- this.props.paginationCallback({'currPage':current})
- }
- render() {
-
- const columns = this.columns.map(col => {
- if (!col.editable) {
- return col;
- }
- return {
- ...col,
- onCell: record => ({
- record,
- }),
- };
- });
- const {
- currPage,
- totalCount,
- } = this.props.pages;
- const paginationProps = {
- showSizeChanger: false,
- showQuickJumper: false,
- showTotal: () => `共${totalCount}条`,
- pageSize: 10,
- current: currPage,
- total: totalCount,
- onChange: (current) => this.changePage(current),
- }
- return (
- <Table
- bordered
- loading={this.state.loading}
- pagination={paginationProps}
- dataSource={this.state.data}
- columns={columns}
- rowClassName="editable-row"
- />
- );
- }
- }
- const EditableFormTable = Form.create()(EditableTable);
- export default EditableFormTable;
|