ant.design rowSelection

rowSelection

type

  • type: ‘checkbox’ 复选框支持全选反选
  • type: ‘radio’ 单选

selectedRowKeys (配合onChange使用)

	const rowSelection = {
      type: 'checkbox',
      selectedRowKeys,
      onChange: this.onSelectChange,
    };
	
	onSelectChange = (selectedRowKeys, selectedRows) => { //选中项发生变化回调
		//自定义选中规则
	    this.setState({
	      selectedRowKeys,
	      selectedRows
	    });
	    console.log(selectedRows, selectedRowKeys)
  }
  //1、注意这里一定要给表格配置rowKeys属性,标记数据的唯一性
  //2、state里一定要设定selectedRowKeys的初始值,不然不能切换选中

getCheckboxProps

  • 自定义禁止使用规则
	const rowSelection = {
      type: 'checkbox',
      selectedRowKeys,
      onChange: this.onSelectChange,
      getCheckboxProps: (record) => this.handleTabledisabled(record),
    };


	handleTabledisabled = (record) => { //禁用已选
	    const { showSelectGoods } = this.state; //已经选中的数据
	    if (showSelectGoods.length > 0) {
	      let addDeliverData = showSelectGoods;
	      addDeliverData = addDeliverData.filter((item) => (item.outGoodsId === record.outGoodsId)); //过滤表格数据和已选中数据
	      return {
	      //返回禁用规则
	        disabled: record.outGoodsId === (addDeliverData.length ? addDeliverData[0].outGoodsId : false),
	      };
	    } else {
	      return {
	        disabled: false,
	      };
	    }
  }

pagination

这里我的后台数据接口时:

	{
		pageNum: 1
		pageSize: 20
		total: 110
		pages: 6
		resultData: [.......表格数据]
	}
 <Table
 	  loading={this.props.Loading}
	  columns={tableColumns}
	  rowKey={(record) => record.id}
	  dataSource={list.resultData ? list.resultData : []}
	  pagination={{
	    total: list.total ? list.total : 0,
	    showSizeChanger: true,
	    current: list.resultData ? list.pageNum : 1,
	    pageSize: this.state.spreadFormParam.pageSize,
	    showTotal: (_total) => `共 ${list.total ? list.total : 0} 条记录`,
	    hideOnSinglePage: !(list && list.pages > 1),
	    onChange: this.handlePageNumChange,
	    onShowSizeChange: this.handlePageSizeChange,
	    showQuickJumper: { goButton: <Button type="primary" style={{marginLeft: '5px'}}>确定</Button> },
	 }}
> 

api解释: https://ant.design/components/pagination-cn/#API

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值