javascript - 使用 react-bootstrap-table-next 按默认降序对最后更新的条目进行排序
问题描述
默认情况下按降序排列最后更新的条目。我试过下面的代码它不起作用,有人可以帮我吗?
它下面的初始代码基于月份而不是基于年份对最后更新的日期进行排序(因为 listLastUpdated 是作为字符串发送的) 例如:当我排序时 01-10-2022 比 11-10-2021 排在前面,当你按升序排序时order 因为日期被视为字符串而不是日期
listLastUpdated: (((new Date(updated_at).getMonth() > 8) ? (new Date(updated_at).getMonth() + 1) : ('0' + (new Date(updated_at).getMonth() + 1))) + '-' + ((new Date(updated_at).getDate() > 9) ? new Date(updated_at).getDate() : ('0' + new Date(updated_at).getDate())) + '-' + new Date(updated_at).getFullYear().toString().substr(-4))
{
text: "LAST UPDATED",
dataField: 'listLastUpdated',
sort: true
}
我通过引用https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/column-props.html进行了如下尝试 注意:使用 react-bootstrap-table-next 插件进行排序
{
text: "LAST UPDATED",
dataField: 'listLastUpdated',
sort: true,
sortFunc: (a, b, order, dataField, rowA, rowB) => {
if (order === 'asc') {
return b - a;
}
return a - b; // desc
}
}
解决方案
推荐阅读
- php - Renaming the product tab-title for WooCommerce Version 2.6.13
- xamarin - How to detect if user requested a tab change on TabbedPage in Xamarin.Forms
- meteor - 如何将数据传递到Framework7中的模板中?
- ios - 将 UIDocumentInteractionController 中的预览呈现为 UIViewController 的 ChildViewController
- node.js - 如何在 Electron 应用程序上获得圆角?
- javascript - 更新 $scope 但 $watch 未检测到的 Mousetrap 键绑定。
- javascript - 双括号 但不是 IIFE 或闭包,它是什么?它是有效的 JS 语法吗?
- google-sheets - 引用单元格文本的 Google 表格查询
- amazon-dynamodb - DynamoDB 表未在 serverless.yml 文件中创建
- r - 在 apply 的函数中使用 dplyr::group_by