【发布时间】:2020-11-02 12:34:14
【问题描述】:
我已经实现了 dataTable 并按照我想要的顺序对数据进行排序。 但我想最后放置空值。而真正有价值的记录应该在最前面。
例子:
<tr>
<td>D</td>
</tr>
<tr>
<td>A</td>
</tr>
<tr>
<td>Z</td>
</tr>
<tr>
<td>-</td>
</tr>
<tr>
<td>B</td>
</tr>
<tr>
<td>-</td>
</tr>
这是我的自定义排序代码:
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"alphbets-pre": function ( a ) {
return jQuery.inArray( a, ["B","D","A","Z"] );
},
"alphbets-desc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alphbets-asc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
这个工作非常好。 使用代码获得这些结果:
ASC DESC
--------------- ---------------
+ Alphabets + + Alphabates +
--------------- ---------------
+ B + + - +
--------------- ---------------
+ D + + - +
--------------- ---------------
+ A + + Z +
--------------- ---------------
+ Z + + A +
--------------- ---------------
+ - + + D +
--------------- ---------------
+ - + + B +
--------------- ---------------
我想要排序:
ASC : B => D => A => Z => - => -
DESC: Z => A => D => B => - => -
有什么解决办法吗?
【问题讨论】:
标签: javascript jquery datatable logic