当前位置:网站首页>在已经知道表格列勾选一个显示一列
在已经知道表格列勾选一个显示一列
2022-07-04 06:41:00 【爱技术的大仙】
import React, {
useEffect, useState} from 'react';
import {
Table,Checkbox,} from 'antd'
const columns = [
{
title: 'ID',
dataIndex: 'user_id',
key: 'user_id',
width: 100,
},
{
title: '昵称',
dataIndex: 'nickname',
key: 'nickname',
width: 150,
},
{
title: '手机号',
dataIndex: 'phone',
key: 'phone',
width: 150,
},
{
title: '余额',
dataIndex: 'balance',
key: 'balance',
width: 150,
},
{
title: '平台服务费',
dataIndex: 'service_charge',
key: 'service_charge',
width: 150,
},
{
title: '性别',
dataIndex: 'sex',
key: 'sex',
width: 150,
},
{
title: '连续登录天数',
dataIndex: 'login_day',
key: 'login_day',
width: 200,
},
{
title: '最大连续登录天数',
dataIndex: 'login_bigday',
key: 'login_bigday',
width: 200,
},
{
title: '登陆时间',
dataIndex: 'login_time',
key: 'login_time',
width: 200,
},
{
title: '加入时间',
dataIndex: 'join_time',
key: 'join_time',
width: 200,
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
width: 150,
},
]
//下拉
const plainOptions = [
{
label: 'ID', value:'user_id' },
{
label: '昵称', value: 'nickname'},
{
label: '手机号', value:'phone' },
{
label: '余额', value: 'balance'},
{
label: '平台服务费', value:'service_charge'},
{
label: '性别', value: 'sex' },
{
label: '连续登录天数', value:'login_day' },
{
label: '最大连续登陆天数', value: 'login_bigday'},
{
label: '登陆时间', value:'login_time' },
{
label: '加入时间', value: 'join_time'},
{
label: '状态', value:'status'},
];
const TableTreeChange = () => {
//把选中的value设置成响应式的用于更新界面
const [selectColum,setSelectColum]=useState(columns)
//原始默认选中的value值
const [checkedList, setCheckedList] = useState(['user_id']);
// 把你勾选到的多选放到一个数组里面
const onChange = (list) => {
setCheckedList(list)
};
useEffect(() => {
console.log(checkedList,66666666666666666)
//使用双重for循环将选中的value和表格中的列中的key值联系起来
let newList=[]
for (let i = 0; i < checkedList.length; i++){
for (let j = 0; j < columns.length; j++){
if (checkedList[i] == columns[j].key) {
newList.push(columns[j]);
}
}
}
//下面部分代码是为了给表格添加一个固定的操作列,如果不需要可以忽略
newList.push({
title: '操作',
key: 'action',
render: (text, record) => (
<span>
<a>edit</a>
</span>
),
width: 100,
fixed: 'right',
})
setSelectColum(newList)
}, [checkedList])
return (
<div>
<Table
columns={
selectColum}
pagination={
false}
/>
<Checkbox.Group options={
plainOptions} value={
checkedList} onChange={
onChange} />
</div>
);
};
export default TableTreeChange;
边栏推荐
- SQL join, left join, right join usage
- Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
- Code rant: from hard coding to configurable, rule engine, low code DSL complexity clock
- 树形dp
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- 24 magicaccessorimpl can access the debugging of all methods
- 高薪程序员&面试题精讲系列119之Redis如何实现分布式锁?
- MySQL 45 lecture learning notes (VII) line lock
- Cervical vertebra, beriberi
- regular expression
猜你喜欢

树形dp
![[backpack DP] backpack problem](/img/7e/1ead6fd0ab61806ce971e1612b4ed6.jpg)
[backpack DP] backpack problem

SQL injection SQL lab 11~22

How to use multithreading to export excel under massive data? Source code attached!

what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!

C language - Blue Bridge Cup - Snake filling

【问题记录】03 连接MySQL数据库提示:1040 Too many connections

selenium驱动IE常见问题解决Message: Currently focused window has been closed.

【MySQL】数据库视图的介绍、作用、创建、查看、删除和修改(附练习题)

centos8安装mysql.7 无法开机启动
随机推荐
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
Mysql 45讲学习笔记(十)force index
Tar source code analysis 8
Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
Mysql 45讲学习笔记(十一)字符串字段怎么加索引
CORS is not intended to protect API endpoints - nikofischer
Tar source code analysis Part 2
Data analysis notes 09
tars源码分析之10
Distributed cap theory
R统计绘图-随机森林分类分析及物种丰度差异检验组合图
Internet of things protocol ZigBee ZigBee module uses the concept of protocol stack
Tar source code analysis 6
Common JS tool Libraries
Abap:ooalv realizes the function of adding, deleting, modifying and checking
MySQL 45 lecture learning notes (x) force index
tars源码分析之6
Dimension and format of data
uniapp 自定義環境變量
Can the out of sequence message complete TCP three handshakes