reactjs - 当 React-Table (v6) Tree Table 段打开时,如何运行函数?
解决方案
关键是onExpandedChange
道具。
const toArray = iterable => [].slice.call(iterable)
const Table = () => {
const $tableWrapper = useRef()
const getGroupFromIndexPath = indexPath => {
return indexPath.reduce(($parentElem, index) => {
return toArray($parentElem.children).filter($child => $child.classList.contains('rt-tr-group'))[index]
}, $tableWrapper.current.querySelector('.rt-tbody'))
}
return (
<div ref={$tableWrapper}>
<ReactTable
data={data}
columns={columns}
pivotBy={['name']}
// I have no idea what the 1st parameter value is supposed to represent:/
onExpandedChange={(value1, indexPath, event, rowData) => {
const $parentGroup = getGroupFromIndexPath(indexPath)
const $childGroup = $parentGroup.querySelector('.rt-tr-group')
if ($childGroup) {
// The expander is open
} else {
// The expander is closed
}
}}
/>
</div>
)
}
推荐阅读
- android - 在 Android 8 上更改我的应用程序中的语言
- yii2 - 如何从 Yii2 基本禁用引导程序?
- python - 在一堆系列上应用 autocorr
- python - Celery AttributeError:异步错误
- c++ - 使用输入/输出文件打印名称、平均值、最高/最低平均值的 C++ Batting Average 程序故障
- firebase - 已应用 AB 测试配置,但 firebase 控制台显示 0 个用户
- ruby-on-rails - 在 Heroku 上加载应用程序时出错
- ios - 无法使用 tabbar swift 在当前上下文中显示控制器
- c# - Prism WPF:在启动时加载用户控件
- c++ - G++ 编译:在 Ubuntu 18.04 上未定义对 `ATL_<...>' 的引用