zoukankan      html  css  js  c++  java
  • 【react+antd】当你使用了可选择的table【rowSelection】,却在操作后无法清除已选择状态

    可以在rowSelection对象内声明selectedRowKeys,通过改变它来控制表格的选中状态:

    const [selectKeys, setSelectedKeys] = useState<any[]>([]);
    
    
        // 通过 rowSelection 对象表明需要行选择
        const rowSelection = {
            selectedRowKeys: selectKeys,
            onChange(selectedRowKeys: any, selectedRows: any) {
                setSelectRows(selectedRows);
                setSelectedKeys(selectedRowKeys)
            },
            onSelect(_: any, __: any, selectedRows: any) {
                setSelectRows(selectedRows);
            },
            onSelectAll(_: any, __: any, selectedRows: any) {
                setSelectRows(selectedRows);
            }
        };
    
    // 操作事件
        // 确定提交
        const rowsSubmit = async () => {
            const param = {
                tagId: tagId || '',
                storeIds: selectRows ? selectRows.map((item: any) => item.id) : []
            };
            const result = await relaStores(param);
            if (result.messageType === 'SUCCESS') {
                message.success(result.messageContent);
                handleSearch();
                handleSearchRelaed();
                setSelectRows([])
                setSelectedKeys([])
            } else {
                message.error(result.messageContent);
            }
        };
    
    
    // 表格:
    <Table
                            dataSource={data}
                            columns={columns}
                            rowKey="id"
                            expandTableParame={{ rowSelection }}
                            key="搜索店铺"
                        />
    

      

  • 相关阅读:
    python-函数作用域
    python-yield
    python-内置函数
    python-迭代和递归
    Command /usr/bin/codesign failed with exit code 1
    vue-infinite-scroll 自动加载
    git登陆迁移 SourceTree 不能自动识别
    Xcode不自动提示代码
    NSTimer的循环引用
    iOS autolayout 代码,自定义间距
  • 原文地址:https://www.cnblogs.com/nangras/p/13878049.html
Copyright © 2011-2022 走看看