首页 > 其他分享 >ProTable rowSelection 支持多选

ProTable rowSelection 支持多选

时间:2024-08-12 17:09:00浏览次数:5  
标签:rowSelection const 多选 abi targetKeyArr ProTable selectedRows allEventArr any

前言:第一次用到多选,gpt非常好用,比之前网页方便太多。

 

import ProTable from '@ant-design/pro-table';
import React, { useState } from 'react';
 
const TableWithRowSelection = () => {
  // 使用 useState 钩子来保存选中的行
  const [selectedRows, setSelectedRows] = useState([]);
 
  // 定义行选择的配置
  const rowSelection = {
    onChange: (selectedRowKeys, selectedRows) => {
      // 当选中的行发生变化时,更新状态
      setSelectedRows(selectedRows);
    },
    // 初始化时选中的行
    selectedRowKeys: selectedRows.map((item) => item.key),
  };
 
  return (
    <ProTable
      rowSelection={rowSelection}
      // ... 其他 ProTable 属性
    />
  );
};
 
export default TableWithRowSelection;

 

结合自己的业务:

1,批量添加事件监控

// 功能3:批量
    // 使用 useState 钩子来保存选中的行
    const [selectedRows, setSelectedRows] = useState<ContractItem[]>([]);// useState([]);

// 功能3:批量

    // 定义行选择的配置
    const rowSelection = {
      onChange: (selectedRowKeys: any, selectedRows: any) => {
        console.log('selectedRowKeys, selectedRows:', selectedRowKeys, selectedRows);
        // 当选中的行发生变化时,更新状态
        setSelectedRows(selectedRows);
      },
      // 初始化时选中的行
      selectedRowKeys: selectedRows.map((item: any) => item.id),
    };

    const _checkSameValueForKey = (arr: any, key: string) => {
      return arr.every(function(obj: any, index: number, array: any) {
        return index === 0 || obj[key] === array[0][key];
      });
    }
    const batch_update_sub_event = () => {
      if (!_checkSameValueForKey(selectedRows, 'abi_hash')) {
        message.warning("只有ABI-Hash相同才能批量配置事件,请先确保ABI-Hash相同。")
        return false
      }
      // 弹窗,提交
      // 先算出所有勾选合约的事件列表。如果是普通成员,则批量配置时添加的事件不能少于已配置事件列表。部门管理员无限制。
      // console.log('通过,继续')
      let allEventArr: any = []
      let targetKeyArr: any = []
      let idArr: any = []
      let abi_hash = ""
      for ( let i = 0; i < selectedRows.length; i++) {
        allEventArr = allEventArr.concat(selectedRows[i].event.concat(selectedRows[i].event_sub))
        targetKeyArr = targetKeyArr.concat(selectedRows[i].event_sub)
        idArr.push(selectedRows[i].id)
        abi_hash = selectedRows[i].abi_hash
      }
      // console.log(allEventArr, targetKeyArr, idArr, abi_hash)
      allEventArr = Array.from(new Set(allEventArr));
      targetKeyArr = Array.from(new Set(targetKeyArr));
      // console.log(allEventArr, targetKeyArr, idArr, abi_hash)

      const finalAllArr = allEventArr.map((name: any) => {
        return {
          key: name,
          title: name,
          description: name
        }
      })

      showModal(finalAllArr, targetKeyArr, idArr, abi_hash)
    }


// 弹窗2:增减监控事件
    const showModal = (allEventArr: any, targetKeyArr: any, idArr: any, abi_hash: string) => {
      setIsModalOpen(true);

      setEventList(allEventArr)
      setTargetKeys(targetKeyArr)
      setCurrIdArr(idArr)
      setCurrAbiHash(abi_hash)
    };
<Button
                  key="button"
                  disabled={selectedRows.length ? false : true}
                  onClick={() => {
                    batch_update_sub_event();
                  }}
                  type="primary"
                >
                  配置事件
                </Button>,

 

const handleBatchOk = () => {
      let idArr: any = []
      for ( let i = 0; i < selectedRows.length; i++ ) {
        idArr.push(selectedRows[i].id)
      }
      const params = {
        ids: idArr,
        abi: batchAbiValue,
      }
      setBatchModalLoading(true)

      action.contractBatchUpdateABI(params).then(() => {
        message.success('提交成功!')
        setIsBatchModalOpen(false);
        setBatchModalLoading(false);
        setBatchAbiValue('')
        setSelectedRows([]) // 重置
        actionRef.current?.reload();
      }).catch((err: any) => {
        setIsBatchModalOpen(false);
        setBatchModalLoading(false);
        console.log(err);
      })
    };
  
    const handleBatchCancel = () => {
      setIsBatchModalOpen(false)
    };

 

 

 

2,批量修改abi

 

标签:rowSelection,const,多选,abi,targetKeyArr,ProTable,selectedRows,allEventArr,any
From: https://www.cnblogs.com/zccst/p/18355312

相关文章

  • 二次封装antd的ProTable、EditableProTable,结合use-antd-resizable-header,做一个列可
    原先是一个项目模块内需求,迭代的时候领导要求项目全面翻新,所有表格都要可伸缩列如果一个一个页面写伸缩列的话,每个页面都要引用一次use-antd-resizable-header,有点累赘找了网上,暂时没看见这个有人整理这个组件。直接上代码importProTablefrom"@ant-design/pro-table";i......
  • vue3+Element Plus 自定义表格单选 多选
    项目背景:用vue3+elementplus做一套考试系统功能场景:添加试题中分为客观题、主观题两种类型,在客观题会出现单选题、多选题两种类型就会导致单选题只能勾选一个答案、多选题能勾选多个答案。效果图废话不说直接上代码<el-buttonclass="btn"icon="Plus"plainst......
  • uniapp+vue3封装下拉框(支持单选、多选)
    子组件代码<template><viewclass="uni-select-dc"><viewref="select"class="uni-select-dc-select":class="{active:active}"@click.stop="handleSelect">......
  • android RecyclerView 长按之后滑动手指多选
    关键函数与类LinearLayoutManager.canScrollHorizontally()LinearLayoutManager.canScrollVertically()RecyclerView.OnItemTouchListener核心代码mCanRecyclerViewScroll=true;recyclerView.setLayoutManager(newLinearLayoutManager(getContext(),LinearLayoutMana......
  • k3cloud简单账表(组织和客户多选)
    importclrclr.AddReference("System")clr.AddReference("Kingdee.BOS")clr.AddReference("Kingdee.BOS.Core")clr.AddReference("Kingdee.BOS.DataEntity")clr.AddReference("Kingdee.BOS.App")clr.AddReference("Ki......
  • 多选项卡的shiny
    下面是一个包含多个选项卡的Shiny应用程序示例代码。在这个例子中,我们创建了一个包含三个选项卡的Shiny应用程序,每个选项卡中都有不同的内容。library(shiny)#DefineUIui<-fluidPage(titlePanel("多选项卡Shiny应用"),tabsetPanel(tabPanel("选项......
  • el-table多选分页回显
    el-table多选分页回显1.多选项添加:reserve-selection="true"<el-table-columntype="selection"align="center"width="55":reserve-selection="true"></el-table-column>reserve-selectio......
  • 一千题,No.0087(多选题常见计分法)
    批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到50%分数;如果考生选择了任何一个错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选项错的人最多。输......
  • 多选列表用法
    文章目录知识回顾使用方法示例代码我们在上一章回中介绍了扩展内容相关的知识,本章回中将介绍单选列表和复选列表.闲话休提,让我们一起TalkFlutter吧。知识回顾我们在本章回中将介绍单选和复选列表,它们是常用的组件,不只在移动平台中使用,在其它平台上也经常被使用,......
  • C语言期末复习多选题50道(含答案)
    答案:1·BCD·2.ABC·3.A·4.AC·5.ABC·6.BCD·7.ACD·8.BD·9.BC·10.BCD·11.ABD·12.ABD·13.ABD·14.AB·15.BCD·16.BCD·17.CD·18.AB·19.BD·20.ABD·21.CD·22.ABD·23.CD·24.C·25.ABD......