javascript - 反应表头的自定义排序方法
问题描述
我需要根据单击的列标题根据不同的值对反应表进行排序。到目前为止,这是我的代码:
{
sortMethod: (a: ListItem, b: ListItem) => {
console.log(a, b);
return 1;
},
Header: (rest) => {
console.log(rest);
return (
<Flex height={16} width="100%" justifyContent="center">
<Text onClick={() => rest.column.sortMethod()} color="black">Name</Text>
</Flex>
);
},
accessor: 'product.name',
minWidth: 280,
},
这是我的桌子:
<Table
key={`table.${products.length}.${selectedKeys.join('.')}`}
isSelectable
showPagination={showPagination}
defaultPageSize={defaultPageSize}
pageSizeOptions={pageSizes}
onSelectionChange={(newSelectedProducts: ListItem[]) => {
if (tableProductsWithTags.length > 0) {
setSelectedProducts(newSelectedProducts.filter(Boolean));
}
}}
noDataText={isLoading ? 'Loading ...' : 'No products'}
columns={projectColumns}
selectedKeys={selectedKeys}
keyField="id"
defaultSorted={sortingOptions}
data={tableProductsWithTags}
getTrProps={() => {
return { style: { alignItems: 'start' }, passthrought: { onClick: setFilterOption } };
}}
getTdProps={
((_state, _rowInfo, column: { id: string }) => {
const tdProps: { [key: string]: any } = {
style: { minHeight: 55 }
};
if (column.id === 'tags') {
tdProps.passthrough = { onEdit: handleEditProduct };
}
return tdProps;
}) as ComponentPropsGetterRC
}
{...props}
/>
将排序传递给sortMethod
道具似乎是正确的方法,但我该如何实际实现呢?在表格中,您可以看到我传入了一个onEdit
在编辑单元格时处理的方法。我也尝试过这种方式来获取标题,但似乎它无法访问相同的道具。
解决方案
推荐阅读
- python - 检查 Pandas DataFrame 单元格是否包含某些字符串
- python-3.x - 我使用 Open CV 使用 Python 获取图像差异,但代码不起作用
- bash - 使用 bash 脚本迭代地运行带有参数的 C++ 程序
- java - 实现 onSaveInstanceState 并自定义它以在旋转屏幕后保存文本后应用程序崩溃
- c# - 链接实体在 Core 中编辑时忘记其 ID 导致错误 - 需要保存在不可见的控制器中
- javascript - Javascript 如何处理导出的模块级变量?
- r - 试图在 R 中传播数据帧
- angularjs - 从导入的模型中调用时,createInput() 的行为不符合预期
- r - 使用 zoo 对象创建多个滞后变量
- maven - mvn verify sonar:sonar 命令是否将代码推送到声纳 Web 仪表板?