Element UI设置列表时间倒序/正序排序展示

在 Element UI 的 el-table 中,可以通过设置 :sort-by 属性来指定表格列的排序属性。那么,如果要按时间倒序排序,只需要将 :sort-by 属性设置为日期字段名,同时在这个字段前加上符号“-”,表示降序排列。

因此,可以按以下步骤实现将 el-table-column 根据时间倒序排序:

  1. 在 el-table-column 上设置 :sortable 属性为 true,开启该列排序功能。
 

html复制代码

<el-table-column label="待排序日期" align="center" prop="paixuDate" :sortable="true"/>

  1. 在 el-table-column 上设置 :sort-by 属性为降序排序的日期字段名(即带有“-”的日期字段名)。
 

html复制代码

<el-table-column label="待排序日期" align="center" prop="paixuDate" :sortable="true" :sort-by="'-paixuDate'"/>

这样就可以实现对 el-table-column 按时间倒序排序了。最后,需要注意的是,使用 Element UI 的 el-table 进行排序时,日期数据需要以时间戳形式进行排序,否则会出现不正确的排序结果。