react-virtualized - React-virtualized Multiple Column Sort,加载后排序
问题描述
我已经为多排序列实现了 VirtualizedTable。我发现您无法在渲染后对其他列进行排序。
以下是我在课堂上的排序功能
sort = ({ event, sortBy, sortDirection }) => {
const nosort = ['input', 'textarea', 'select', 'option', 'span'].indexOf(event.target.tagName.toLowerCase()) !== -1
if (!nosort && this.props.disableSort !== true) {
this.setState((prevState, props) => ({ sortBy, sortDirection: sortBy === prevState.sortBy ? sortDirection : 'ASC' }))
}
}
根据文档,这是我的 sortState
sortState = () => createTableMultiSort(this.sort, defaultSort);
以下是我作为道具注入组件的内容
const defaultSort = () => {
return {
defaultSortBy: ['firstColumn', 'secondColumn'],
defaultSortDirection: {
firstColumn: 'ASC',
secondColumn: 'ASC',
}
}
}
这是我的 headerRenderer
headerRenderer = (tableWidth) => ({ columnData, dataKey, disableSort, label, sortBy, sortDirection }) => {
const showSortIndicator = this.sortState().sortBy.includes(dataKey);
return (
<React.Fragment key={dataKey}>
<div className="ReactVirtualized__Table__headerTruncatedText" title={label}>
{label}
</div>
{showSortIndicator && <SortIndicator key="SortIndicator" sortDirection={this.sortState().sortDirection[dataKey]} />}
<Draggable
axis="x"
defaultClassName="DragHandle"
defaultClassNameDragging="DragHandleActive"
onDrag={(event, { deltaX }) => { this.resizeRow({ dataKey, deltaX, tableWidth }) } }
position={{ x: 0 }}
zIndex={999}
>
<span className="DragHandleIcon" title="Drag icon to expand/collapse the column">⋮</span>
</Draggable>
</React.Fragment>
)
我已经通读了代码 createMultiSort 并调试了我自己的代码,看看为什么它不起作用。基本上,showSortIndicator 不正确,因为 sortBy 不包含列键。
我试图在 defaultSort 中输入列的名称作为数据类型。但这似乎不起作用。
渲染后如何对其他列启用排序?如果指定了默认排序,这些列将如何排序?
TIA帕特里克
解决方案
经过一段时间的调试和查看源代码后解决了。似乎您不能将 defaultSortBy 单独指定为元素的道具。您需要在创建元素时指定。因此,根据文档 -
const sortState = createMultiSort(sort, {
defaultSortBy: ['firstName', 'lastName'],
defaultSortDirection: {
firstName: 'ASC',
lastName: 'ASC',
},
});
推荐阅读
- sql - 如何在 MS Access 中对包含与号的记录进行 sql 查询?
- java - 如何发送不止一条消息?
- flutter - 颤振医生 FileSystemException:无法打开文件,路径 = 'C:\Program Files\flutter\version'(操作系统错误:权限被拒绝,errno = 5)
- c - mkstemp 和硬盘压力
- c# - OrderBy 排序并发症
- node.js - 如何检查 ndjson 格式验证?
- python-3.x - 更改字典列表中特定键的值
- qt - QTableWidget setCellWidget(QWidget *)与单元格选择和焦点不一致的行为
- html - 即使在滚动时如何让覆盖覆盖整个页面
- excel - 彭博函数引用导致运行时错误