Datatables 数据表中的多列排序
我有一个表,它有8列。假设它们的标题是'A','B'..'H’ 我想应用多列排序,如: 默认视图:案例1:如果用户单击“A”,则将列排序为“A”(描述)->“B”(asc)->“E”(asc)->…”H'(asc) 若用户再次点击“A”,那个么什么也不会发生 案例2:如果用户单击“E”,则将列排序为“E”(asc)->“A”(描述)->“B”(asc)->“F”(asc)->…”H'(asc) 若用户再次点击“E”,那个么什么也不会发生 案例3:如果用户单击“F”,则将列排序为“F”(asc)->“A”(描述)->“B”(asc)->“E”(asc)->…”H'(asc) 若用户再次点击“F”,那个么什么也不会发生 请看代码我做了什么Datatables 数据表中的多列排序,datatables,jquery-plugins,Datatables,Jquery Plugins,我有一个表,它有8列。假设它们的标题是'A','B'..'H’ 我想应用多列排序,如: 默认视图:案例1:如果用户单击“A”,则将列排序为“A”(描述)->“B”(asc)->“E”(asc)->…”H'(asc) 若用户再次点击“A”,那个么什么也不会发生 案例2:如果用户单击“E”,则将列排序为“E”(asc)->“A”(描述)->“B”(asc)->“F”(asc)->…”H'(asc) 若用户再次点击“E”,那个么什么也不会发生 案例3:如果用户单击“F”,则将列排序为“F”(asc)-
$(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": ""
},
$(文档).ready(函数(){
pushState(“对象或字符串”、“EPAP |拍卖列表”、contextPath+“/auctions/AuctionList”);
languageList.sEmptyTable='';
auctionTable=$('#datatable')。datatable({
语言:语言列表,
订单:[[0,'说明']],
columnDefs:[
{目标:0,orderSequence:['desc']},
{目标:1,orderSequence:['asc']},
{目标:4,orderSequence:['asc']},
{目标:5,顺序:['asc']},
{目标:6,orderSequence:['asc']},
{目标:7,orderSequence:['asc']},
{类型:“日期时间时刻”,目标:5}
],
initComplete:函数(){
$('#datatable th')。在('click',函数(事件){
var auctionTable=$('#datatable').datatable();
var th=$(this.nextest('th');
var colIndex=auctionTable.column(th.index();
console.log(colIndex);
如果(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('ordercol6')
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,“ataargets”:[2,3,8]}
] ,
“ajax”:{
“url”:(contextPath+“/auctions/dailyactionviewlist”),
“缓存”:false,
“asyc”:错误,
“dataSrc”:”
},
输出:
我想要什么
提前感谢我找到了解决方案:
$(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]}
]
}); });
请编辑您的问题,以显示您的DataTables代码。请同时显示您已经尝试过的内容。此外,是否足以满足您的需要?这将比您在问题中描述的内容更易于实现。请尽可能不要将您的代码作为链接提供。请在问题本身中发布格式化文本。如果您认为e太长,无法执行此操作,然后将其剥离到相关的(工作!)部分。请参阅。另外,当我单击您提供的链接时,我会看到以下消息:此服务在您的国家/地区不可用。更新了问题,现在请帮助我解决。感谢您的更新。我建议您使用多重排序,甚至只使用默认情况下获得的基本Shift-click多列排序。对于日期和时间您可以使用多种方法。最简单的方法是使用YYYY-MM-DD HH:MM:SS“和24小时符号。如果您想要不同的格式,此网站上已经有各种问题和答案-可能其中一种会有所帮助。尝试了此功能,但未起作用