首页 > 解决方案 > 如何更改 tanstack React Table useSelectRow 的 id

问题描述

嗨,伙计,我只是在 tanstack React Table 上进行构建批量删除实验,问题出在这里我无法更改所选列的 id

我为什么要改变这个?
因为我想要可以发送到服务器的 MongoDB id。
selectedRowIds方法

在此处输入图像描述

这里有一些来自钩子的代码

hooks => {
            hooks.visibleColumns.push(columns => [
                // Let's make a column for selection
                {
                    id: 'selection',
                    // accessor: '_id',
                    // The header can use the table's getToggleAllRowsSelectedProps method
                    // to render a checkbox
                    Header: ({ getToggleAllRowsSelectedProps }) => (
                        <div>
                            <IndeterminateCheckbox {...getToggleAllRowsSelectedProps()} />
                        </div>
                    ),
                    // The   cell can use the individual row's getToggleRowSelectedProps method
                    // to the render a checkbox
                    Cell: ({ row }) => {
                        console.log(row)
                        return <div>
                            <IndeterminateCheckbox {...row.getToggleRowSelectedProps()} />
                        </div>

                    },
                },
                ...columns,
            ])

并且所有完整参考都来自主要文档

标签: reactjsreact-table-v7

解决方案


使用selectedFlatRows是 contian 所有选定的行数据

在此处输入图像描述


推荐阅读