sorting - ag grid react 比较器 - 对具有日期时间和字符串文字的列进行自定义排序
问题描述
我正在尝试对具有日期时间和字符串文字的 ag 网格反应列进行排序。网格 api 数据如下所示:
export const TableData = [ { id: 9890987, createdBy: "john", updatedBy: "john", scriptType: "new", scriptName: "XYZ", scheduleType: "ONCE", nextRunTime: "Never", lastRunTime: "11/10/2009 15:43:17", lastStatus: "Passed", lastError: "" }, { id: 9891287, createdBy: "Ela", updatedBy: "Ela", scriptType: "new2", scriptName: "XYZ", scheduleType: "HOURLY", nextRunTime: "Never", lastRunTime: "11/10/2014 14:42:17", lastStatus: "Passed", lastError: "" }, { id: 6660987, createdBy: "Mandy", updatedBy: "Mandy", scriptType: "new3", scriptName: "UYT", scheduleType: "MONTHLY", nextRunTime: "Never", lastRunTime: "Never", lastStatus: "Passed", lastError: "" } ]
使用 ag-grid 的比较器属性对 lastRunTime 和 nextRunTime 列进行排序,如下所示,不会以正确的升序或降序排序日期时间:
columnDef = [ { headerName: 'Next Run Time', field: 'nextRunTime', width: 150, comparator: (date1, date2)=> new Date(date1) < new Date(date2) ? -1 : 1 }, { headerName: 'Last Run Time', field: 'lastRunTime', width: 150, comparator: (date1, date2)=> new Date(date1) < new Date(date2) ? -1 : 1 } ]
在这种情况下,可以使用什么比较器算法来启用日期时间排序?
解决方案
推荐阅读
- unit-testing - Sitecore 9.2 单元测试错误:找不到配置节点:contentSearch/configuration
- java - 使用 Jersey 的 Java 服务不会部署到 Jboss
- css - 如何正确加载我的 css asp.net Visual Basic
- angular - 我无法返回新的 observable 看起来不起作用
- php - 在 Symfony 中使用迁移时如何保持预先存在的表不变?
- .net - 对于 .NET Core 应用程序,“服务...启动”指令到底意味着什么?
- mariadb - MariaDB 为 ROW 类型的变量动态提取列
- uppaal - 找不到可能导致“由超出范围的分配或超出范围的数组查找引起”的原因。错误
- recursion - Rust 什么时候保证尾递归?
- machine-learning - na.fail.default 中的随机森林错误:对象中的缺失值