datatables - 数据表按编号文档和文档年份排序
问题描述
我不知道如何实现一种简单的方法来对列进行排序,该列向我显示带有尾随年份的文档数量,例如:
COL 1 COL 2 COL 3 DOC. NR
------------------------------------
x x x 2/2020
------------------------------------
x x x 3/2020
------------------------------------
x x x 4/2021
------------------------------------
x x x 1/2022
------------------------------------
在我的示例中,我想doc. nr
根据文档的数量(按年份分组)按 asc 或 desc 对 col 进行排序。
我尝试使用公式设置数据顺序:numberdoc + year
但它不起作用,例如,3 + 2020 等于 1 + 2022....所以这种方式是不正确的。任何想法?
<td data-order="2020">1/2019</td>
脚本:
$(document).ready( function () {
var table = $('#example').DataTable({
"aaSorting": [[ 1, "desc" ]],
"columnDefs": [
{
targets: [1],
data: {
_: "1.display",
sort: "1.@data-order",
type: "1.@data-order"
}
}
]
});
} );
我的小提琴: http: //live.datatables.net/jivekefo/1/edit
预期(ASC)结果:
1/2018
2/2018
3/2018
1/2019
2/2019
3/2019
4/2019
1/2020
...
解决方案
好的解决了这个规则:
<td data-order="<?php echo (new Datetime($dateDoc))->format("Y") . str_pad(ltrim($numberDoc, "0"), 5, "0", STR_PAD_LEFT); /* example. 201900001 */ ?>">
推荐阅读
- c++ - C++ 标准库中是否有保证不执行动态内存分配的函数或类?
- excel - 如何为通过 Excel 中的自定义功能区调用的脚本提供用户参数?
- excel - 是否可以在excel中计算这个系列总和?
- c++ - 改进三重递归函数
- windows - windows下如何从MinGW获取gcc/g++执行的程序的内存使用情况
- apache-nifi - 当流版本更改时,流文件会发生什么?
- python - 如何匹配ip地址
- javascript - 从 url 中删除 # 字符
- javascript - daterangepicker isInvalidDate() 无法正常工作
- excel - 根据拆分单元格文本将工作表行复制到新工作表