首页 > 其他 > 详细

react antd3.0 table

时间:2020-05-03 15:14:06      阅读:46      评论:0      收藏:0      [点我收藏+]
import React, { Component } from ‘react‘
import Axios from ‘axios‘;
import qs from ‘qs‘
import api from  ‘@/services/api‘
import { Table } from ‘antd‘;

export default class TableDemo extends Component {
  state = {
    selectedRowKeys: [],
    data: [],
    total: ‘‘
  };

  componentDidMount () {
   this.initData(1)
  }

  initData(current){
    Axios.post(api.limitData,qs.stringify({page: current, limit: 5})).then(res=>{ //这里是请求的自己的数据
      this.setState({
        data: res.data.result.list,
        total: res.data.result.count
      })
    })
  }
  // 多选
  onSelectChange = selectedRowKeys => {
    this.setState({ selectedRowKeys });
  };
  // 删除
  onDelete = option => {
    // console.log(option)
  }
  // 获取分页器页码
  limitData = current => {
    this.initData(current)
  }

  render() {
    const columns = [
      {
        title: ‘Id‘,
        dataIndex: ‘id‘,
        sorter: (a, b) => a.id - b.id,  //排序
      },
      {
        title: ‘Title‘,
        dataIndex: ‘title‘,
      },
      {
        title: ‘Tags‘,
        dataIndex: ‘tags‘,
      },
      {
        title: ‘Thumb‘,
        dataIndex: ‘thumb‘,
        render: record => (  
          <img src=‘/logo192.png‘  style={{width:‘50px‘,height:‘50px‘,borderRadius:‘50%‘}}/>
        ),
      }, 
      {
        title: ‘Action‘,
        dataIndex: ‘action‘,
        render: (text, record) => (
          <span>
            <a onClick={()=>this.onDelete(text)}>Delete</a>
          </span>
        ),
      },
    ];
    // 多选
    const { selectedRowKeys } = this.state;
    const rowSelection = {
      selectedRowKeys,
      onChange: this.onSelectChange,
    };
    const hasSelected = selectedRowKeys.length > 0;
    // 多选
    // 分页器
    const pagination = {
      pageSize: 5,
      onChange: this.limitData,
      total: +this.state.total
    }
    return (
      <>
        <div style={{ marginBottom: 16 }}>
          <span style={{ marginLeft: 8 }}>
            {hasSelected ? `已选中 ${selectedRowKeys.length} 条数据` : ‘‘}
          </span>
        </div>
        <Table 
          rowKey="id"
          columns={columns}  
          dataSource={this.state.data}
          rowSelection={rowSelection} //checkbox
          pagination={pagination}     //分页器  
        />
      </>
    )
  }
}

  

import React, { Component } from ‘react‘
import Axios from ‘axios‘;
import qs from ‘qs‘
import api from  ‘@/services/api‘
import { Table } from ‘antd‘;

export default class TableDemo extends Component {
  state = {
    selectedRowKeys: [],
    data: [],
    total‘‘
  };

  componentDidMount () {
   this.initData(1)
  }

  initData(current){
    Axios.post(api.limitData,qs.stringify({pagecurrentlimit5})).then(res=>//这里是请求的自己的数据
      this.setState({
        datares.data.result.list,
        totalres.data.result.count
      })
    })
  }
  // 多选
  onSelectChange = selectedRowKeys => {
    this.setState({ selectedRowKeys });
  };
  // 删除
  onDelete = option => {
    // console.log(option)
  }
  // 获取分页器页码
  limitData = current => {
    this.initData(current)
  }

  render() {
    const columns = [
      {
        title‘Id‘,
        dataIndex‘id‘,
        sorter: (ab=> a.id - b.id,  //排序
      },
      {
        title‘Title‘,
        dataIndex‘title‘,
      },
      {
        title‘Tags‘,
        dataIndex‘tags‘,
      },
      {
        title‘Thumb‘,
        dataIndex‘thumb‘,
        renderrecord => (  
          <img src=‘/logo192.png‘ alt="" style={{width:‘50px‘,height:‘50px‘,borderRadius:‘50%‘}}/>
        ),
      }, 
      {
        title‘Action‘,
        dataIndex‘action‘,
        render: (textrecord=> (
          <span>
            <a onClick={()=>this.onDelete(text)}>Delete</a>
          </span>
        ),
      },
    ];
    // 多选
    const { selectedRowKeys } = this.state;
    const rowSelection = {
      selectedRowKeys,
      onChangethis.onSelectChange,
    };
    const hasSelected = selectedRowKeys.length > 0;
    // 多选
    // 分页器
    const pagination = {
      pageSize5,
      onChangethis.limitData,
      total+this.state.total
    }
    return (
      <>
        <div style={marginBottom16 }}>
          <span style={marginLeft8 }}>
            {hasSelected ? `已选中 ${selectedRowKeys.length} 条数据` : ‘‘}
          </span>
        </div>
        <Table 
          rowKey="id"
          columns={columns}  
          dataSource={this.state.data}
          rowSelection={rowSelection} //checkbox
          pagination={pagination}     //分页器  
        />
      </>
    )
  }
}

react antd3.0 table

原文:https://www.cnblogs.com/yetiezhu/p/12821833.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!