当前位置:网站首页>在已经知道表格列勾选一个显示一列
在已经知道表格列勾选一个显示一列
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;
边栏推荐
- Mysql 45讲学习笔记(十二)MySQL会“抖”一下
- Analysis of tars source code 5
- C實現貪吃蛇小遊戲
- Shopping malls, storerooms, flat display, user-defined maps can also be played like this!
- 雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)
- Common usage of time library
- 运算符<< >>傻瓜式测试用例
- Redis interview question set
- Is the insurance annuity product worth buying? Is there a hole?
- Tar source code analysis 8
猜你喜欢
Variables d'environnement personnalisées uniapp
C实现贪吃蛇小游戏
centos8安装mysql.7 无法开机启动
SQL join, left join, right join usage
uniapp 自定義環境變量
[Android reverse] function interception (CPU cache mechanism | CPU cache mechanism causes function interception failure)
雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)
MySQL 45 lecture learning notes (VII) line lock
Cloud native - SSH article that must be read on the cloud (commonly used for remote login to ECS)
selenium IDE插件下载安装使用教程
随机推荐
C # symmetric encryption (AES encryption) ciphertext results generated each time, different ideas, code sharing
InputStream/OutputStream(文件的输入输出)
Analysis of tars source code 5
Displaying currency in Indian numbering format
内卷怎么破?
Overview of convolutional neural network structure optimization
GoogleChromePortable 谷歌chrome浏览器便携版官网下载方式
Bicolor case
MySQL 45 lecture learning notes (XIII) delete half of the table data, and the table file size remains the same
微信小程序使用rich-text中图片宽度超出问题
Another company raised the price of SAIC Roewe new energy products from March 1
2022 Xinjiang's latest eight members (Safety Officer) simulated examination questions and answers
Operator < <> > fool test case
雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)
1、 Relevant theories and tools of network security penetration testing
What is the "relative dilemma" in cognitive fallacy?
Arcpy 利用updatelayer函数改变图层的符号系统
Uniapp custom environment variables
[number theory] fast power (Euler power)
Software keywords and process information intercepted by Golden Shield video player