我有一个表,它有8列。假设它们的标题是'A','B'......'H'。'H'.
我想应用多列排序,如:"A","B"...... "H"。
默认视图: Case1: 如果用户点击'A',然后将该列排序为'A'(降)- > 'B'(升)- > 'E'(升)- >......。- > 'H' (升)
如果用户再次点击'A',则不会发生任何事情。
案例2:如果用户点击'E',然后将该列排序为'E'(升)->;'A'(降)->;'B'(升)->;'F'(升)->;......。- >'H'(升)- >'B'(升)- >'F'(升)- >....
如果用户再次点击'E',则不会发生任何事情。
案例3:如果用户点击'F',然后将该列排序为'F'(升)->'A'(降)->'B'(升)->'E'(升)->...。- >'H'(升)- >'B'(升)- >'E'(升)- >....
如果用户再次点击'F',则不会发生任何事情。
请看我所做的代码
$(document).ready(function() {
window.history.pushState("object or string", "EPAP|AuctionList", contextPath+"/auctions/auctionlist");
languageList.sEmptyTable = '<spring:message code="auctionlist.emptytable"/>';
auctionTable = $('#datatable').DataTable({
language: languageList,
order: [[0, 'desc']],
columnDefs: [
{targets: 0, orderSequence: ['desc']},
{targets: 1, orderSequence: ['asc']},
{targets: 4, orderSequence: ['asc']},
{targets: 5, orderSequence: ['asc']},
{targets: 6, orderSequence: ['asc']},
{targets: 7, orderSequence: ['asc']},
{type: "datetime-moment",targets: 5}
],
initComplete: function () {
$('#datatable th').on('click', function (event) {
var auctionTable = $('#datatable').DataTable();
var th = $(this).closest('th');
var colIndex = auctionTable.column( th ).index();
console.log(colIndex);
if (colIndex === 0) {
console.log('order col 0 ')
auctionTable.order([[0, 'desc'], [1, 'asc'], [4, 'asc'], [5, 'asc'],[6, 'asc'],[7, 'asc']]).draw();
}else if (colIndex === 4) {
console.log('order col 4 ')
auctionTable.order([[4, 'asc'],[0, 'desc'], [1, 'asc'], [5, 'asc'],[6, 'asc'],[7, 'asc']]).draw();
}else if (colIndex === 5) {
console.log('order col 5 ')
auctionTable.order([[5, 'asc'],[0, 'desc'], [1, 'asc'],[4, 'asc'] ,[6, 'asc'],[7, 'asc']]).draw();
}else if (colIndex === 6) {
console.log('order col6 ')
auctionTable.order([[6, 'asc'],[0, 'desc'], [1, 'asc'], [5, 'asc'],[4, 'asc'],[7, 'asc']]).draw();
}else if (colIndex ===7) {
console.log('order col 7')
auctionTable.order([[7, 'asc'],[0, 'desc'], [1, 'asc'], [5, 'asc'],[4, 'asc'],[6, 'asc']]).draw();
}
});
},
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 2,3,8 ] }
] ,
"ajax": {
"url": (contextPath + "/auctions/dailyAuctionViewList"),
"cache": false,
"asyc":false,
"dataSrc": ""
},
我想要什么?
先对0指数列进行排序,然后对1指数进行排序,以此类推
但输出图像中的列没有正确排序。
注意事项 简要说明在 https:/s.docworkspace.comdocs3Hj58r9qB请大家帮帮我,因为我是第一天接触数据表。
先谢谢你
我已经找到了解决方案。
$(document).ready(function() {
var auctionTable = $('#datatable').DataTable({
order:[[0, 'desc']],
columnDefs: [
{targets: 0, orderSequence: ['desc']},
{targets: 1, orderSequence: ['asc']},
{targets: 4, orderSequence: ['asc']},
{targets: 5, orderSequence: ['asc']},
{targets: 6, orderSequence: ['asc']},
{targets: 7, orderSequence: ['asc']},
{orderable: false, targets:[1,2,3,8]}
]
}); });