javascript - 我如何在列标题反应表中检索访问器名称
问题描述
我的列如下:
const columns = React.useMemo(
() => [
{
Header: "Name",
accessor: "name", // accessor is the "key" in the data
},
{
Header: "Email",
accessor: "email",
}
])
我的表格代码片段如下所示:
<table
{...getTableProps()}
id="basicTable"
className="table table-bordered action-table table-striped table-hover mb-0"
>
<thead>
{headerGroups.map((headerGroup) => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((column) => (
<th
{...column.getHeaderProps()}
className="align-top"
>
<div
// {...column.getSortByToggleProps()}
onClick={(e) => {
console.log(
`col ${column.accessor}`
);
}}
>
{column.render("Header")}
</div>
<div>
{column.canFilter
? column.render(
"Filter"
)
: ""}
</div>
</th>
))}
</tr>
))}
</thead>
</table>
现在,在这里,我正在尝试检索访问器,但我无法这样做,在安慰时column.accessor
,它返回:
function accessor(row) {
return getBy(row, accessorPath);
}
如何,我可以获得访问器名称,以便我可以使用 col 名称触发 api 调用进行排序?
更新:
访问器函数如下所示:
解决方案
保留accessor
作为函数有助于处理一些其他功能,对于这个用例,尝试在列配置中保留另一个键(例如 sortByBE)。
推荐阅读
- c# - 我将一个正在运行的项目从一台电脑移动到另一台电脑,现在它提供了与数据库相关的错误
- google-cloud-platform - 指定的提供商“google”不存在
- python - DJANGO CRUD 没有名为“django.contrib.name”的模块
- r - 创建固定长度二进制向量的更快方法:如果固定长度为 6,则 4' 将变为 (0,0,0,1,0,0)
- java - 从 Set (Collection) 中获取任何项目
- sql-injection - 使用 Dynogels 进行 NoSQL 注入
- c++ - 如何检查条件是否为真 5 秒?
- javascript - 如何在 ES6 中扩展从父类继承的类属性?
- docker - 我的 docker 无法使用私有注册表(503 服务不可用)
- dart - 为什么 Dart 隔离中的流在没有接收端口的情况下不起作用