javascript - 如何在 React-Table.js 中隐藏值为 null 的列?
问题描述
我有一个可用的 React 表,其中包含用于查看 Marathon 数据的列。然而,半程马拉松使用除了 2 之外的所有相同的列。如果我的数据有null
一个列,我如何动态地告诉 React-Table 隐藏它?这是Columns
数组中的示例列:
{
id: "time_35k",
Header: "35k",
className: "hide-mobile",
headerClassName: "hide-mobile",
style: {
textAlign: "center"
},
show: true,
accessor: runner => formatTime(runner.time_35k),
getProps: (state, rowInfo, column) => {
if (state.value === null) {
newColumn.show = false;
newColumn.style.display = "none";
newColumn.headerStyle.display = "none";
return {
style: {
display: "none"
},
headerStyle: {
display: "none"
}
};
}
}
},
这是一个示例半程马拉松数据对象:
{
"place": 1,
"name": "Keith Meyer",
"age": 22,
"sex_place": 1,
"sex": "M",
"rank": 2,
"time_5k": 987,
"rank_5k": 1,
"time_10k": 1976,
"rank_10k": 1,
"time_15k": 2981,
"time_35k": null, // TODO: hide this table column
"time": 4202,
"pace": 321,
"city": "Edwardsville",
"state": "IL",
"bib_number": 5011,
"link": "http://www.youtube.com/watch?v=bkirVvr6acU&t=8s"
}
解决方案
我用这个选项解决了这个问题:
//...code definition table here
} = useTable(
{
columns,
data,
initialState: {
pageIndex: 0,
hiddenColumns: ['id']. //use property option, in columns define id name "id"
},
},
usePagination
);
推荐阅读
- forms - Vuetify / Vee Validate 当所有字段都有效时自动提交表单
- javascript - 如何映射对象以在 JS 中获取具有“true”值的键数组?
- r - 将新文件添加到响应式文件路径时,Shiny 中的 reactiveFileReader 不会更新
- reactjs - 将 firebase twitter 身份验证添加到 react js google chrome 扩展
- javascript - 使用 Chrome 扩展在特定网站上执行 JavaScript
- discord.py - 如何在 Discord.py 中为特定的“arg”给出不同的答案
- llvm - 如何在优化的 IR 中从 dbg 获取原始变量名称
- gimp - 如何在 Gimp 中使文本框背景颜色不透明?
- javascript - 为什么此脚本中的实时搜索未显示实时结果?
- python - 运行 django 更新但调用 save 方法