admin 管理员组文章数量: 1086019
I have been working for a couple of days with DataTables and I have this task:
I need to disable the initial sorting and filter the first column which contains dates like Aug 15
depending on the fourth one (2015.08.15
), which will be hidden.
For example, if I have:
Aug 15 | 2015.08.15
Aug 7 | 2015.08.07
Aug 3 | 2015.08.03
Aug 20 | 2015.08.20
In ascending sort I should get:
Aug 3 | 2015.08.03
Aug 7 | 2015.08.07
Aug 15 | 2015.08.15
Aug 20 | 2015.08.20
But I get the alphabetical sort:
Aug 15 | 2015.08.15
Aug 20 | 2015.08.20
Aug 3 | 2015.08.03
Aug 7 | 2015.08.07
My first code was something like:
$("#TableBt" + rid).DataTable({
"aaSorting": [],
"columns": [
null,
null,
{
"title": lC2
},
{
"visible": false
}]
This disabled my initial sorting, but it alphabetical sort my date column (the first and visible one).
After some research, I changed the code like this:
$("#TableBt" + rid).dataTable({
"asSorting": [],
"aoColumnDef": [
{
"iDataSort": 3,
"aTargets": [4]
},
null,
{
"sTitle": lC2
},
{
"bVisible": false,
"aTargets": [3]
}]
});
But now all the columns are visible, the initial sorting is again enable and the date sort works only alphabetical.
What am I doing wrong?
I have been working for a couple of days with DataTables and I have this task:
I need to disable the initial sorting and filter the first column which contains dates like Aug 15
depending on the fourth one (2015.08.15
), which will be hidden.
For example, if I have:
Aug 15 | 2015.08.15
Aug 7 | 2015.08.07
Aug 3 | 2015.08.03
Aug 20 | 2015.08.20
In ascending sort I should get:
Aug 3 | 2015.08.03
Aug 7 | 2015.08.07
Aug 15 | 2015.08.15
Aug 20 | 2015.08.20
But I get the alphabetical sort:
Aug 15 | 2015.08.15
Aug 20 | 2015.08.20
Aug 3 | 2015.08.03
Aug 7 | 2015.08.07
My first code was something like:
$("#TableBt" + rid).DataTable({
"aaSorting": [],
"columns": [
null,
null,
{
"title": lC2
},
{
"visible": false
}]
This disabled my initial sorting, but it alphabetical sort my date column (the first and visible one).
After some research, I changed the code like this:
$("#TableBt" + rid).dataTable({
"asSorting": [],
"aoColumnDef": [
{
"iDataSort": 3,
"aTargets": [4]
},
null,
{
"sTitle": lC2
},
{
"bVisible": false,
"aTargets": [3]
}]
});
But now all the columns are visible, the initial sorting is again enable and the date sort works only alphabetical.
What am I doing wrong?
Share Improve this question edited Sep 19, 2015 at 15:04 Gyrocode. 58.9k16 gold badges156 silver badges191 bronze badges asked Sep 18, 2015 at 12:40 LAffairLAffair 1,9986 gold badges33 silver badges64 bronze badges1 Answer
Reset to default 10SOLUTION
You need to use columnDefs
to target first column (targets: 0
) and define the column which data would be used for sorting of the first column with orderData
. Also you need to hide forth column (targets: 3
) with visible: false
.
$("#TableBt" + rid).DataTable({
columnDefs: [
{ targets: 0, orderData: 3 },
{ targets: 3, visible: false }
]
});
DEMO
See this jsFiddle for code and demonstration.
本文标签: javascriptjQuery DataTablesOrdering dates by hidden columnStack Overflow
版权声明:本文标题:javascript - jQuery DataTables - Ordering dates by hidden column - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743991355a2514785.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论