我正在尝试对具有日期时间和字符串文字的 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 } ]
在这种情况下,可以使用什么比较器算法来启用日期时间排序?