Multi-column sort not working for second click
Multi-column sort not working for second click
maliu1970
Posts: 15Questions: 2Answers: 0
Hi Allan,
I used your code to sort programmatically on two columns but it sorts only the first time. It doesn't sort second time descending. Here's my code. Please help. Thank you.
I want the first column to always be sorted ascending regardless which other column is sorted on.
$(document).ready(function () {
var SortTable = $('#tblUploadHistory').dataTable();
SortTable.fnSortListener(document.getElementById('ValidatedDate'), 1);
$('#Overall').click(function () {
var ColumnSort = SortTable.fnSettings().aaSorting;
if (ColumnSort[0][0] != 2 || ColumnSort[0][1] == 'desc') {
SortTable.fnSort([[4, "asc"], [0, "asc"]]);
}
else {
SortTable.fnSort([[4, 'desc'], [0, 'asc']]);
}
});
});
function PopulateUploadDataTable(FacilityUploadItems) {
var Table = $('#tblUploadHistory').dataTable({
"sScrollY": "255px",
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"bInfo": true,
"bAutoWidth": false,
"aaSorting": [[0, "desc"],
"aaData": FacilityUploadItems,
"aoColumns": [
{ "mDataProp": "Submitted Date", sClass: "tdData" },
{ "mDataProp": "Submitted By", sClass: "tdData" },
{ "mDataProp": "Validated Date", sClass: "tdData",
"mRender": function (data, type, full) {
return '' + $.datepicker.formatDate('mm/dd/yy', new Date(data)) + '';
}
},
{ "mDataProp": "Overall %", sClass: "tdData" },
{ "mDataProp": "Hourly +/-3%", sClass: "tdData" },
{ "mDataProp": "Category +/-3%", sClass: "tdData" },
{ "mDataProp": "CERTIFIED", sClass: "tdData" },
{ "mDataProp": "File Name", sClass: "tdData",
"mRender": function (data, type, full) {
return '' + data + '';
}
}
,
{ "mDataProp": "Validated Date" }
],
"aoColumnDefs": [{ "bVisible": false, "aTargets": [8] },
{ "iDataSort": 8, "aTargets": [2]}],
"bDestroy": true
});
$('#tblUploadHistory').show();
$("#divUploads").show();
setTimeout(function () {
Table.css('width', '100%');
Table.fnAdjustColumnSizing();
}, 10);
}
Facility Name
Submitted Date
Submitted By
Validated Date
Overall %
Hourly +/- 3
Category +/- 3%
Certified
File Uploaded
SortValidatedDate
Thank you very much for your help.
Best regards,
Ali
I used your code to sort programmatically on two columns but it sorts only the first time. It doesn't sort second time descending. Here's my code. Please help. Thank you.
I want the first column to always be sorted ascending regardless which other column is sorted on.
$(document).ready(function () {
var SortTable = $('#tblUploadHistory').dataTable();
SortTable.fnSortListener(document.getElementById('ValidatedDate'), 1);
$('#Overall').click(function () {
var ColumnSort = SortTable.fnSettings().aaSorting;
if (ColumnSort[0][0] != 2 || ColumnSort[0][1] == 'desc') {
SortTable.fnSort([[4, "asc"], [0, "asc"]]);
}
else {
SortTable.fnSort([[4, 'desc'], [0, 'asc']]);
}
});
});
function PopulateUploadDataTable(FacilityUploadItems) {
var Table = $('#tblUploadHistory').dataTable({
"sScrollY": "255px",
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"bInfo": true,
"bAutoWidth": false,
"aaSorting": [[0, "desc"],
"aaData": FacilityUploadItems,
"aoColumns": [
{ "mDataProp": "Submitted Date", sClass: "tdData" },
{ "mDataProp": "Submitted By", sClass: "tdData" },
{ "mDataProp": "Validated Date", sClass: "tdData",
"mRender": function (data, type, full) {
return '' + $.datepicker.formatDate('mm/dd/yy', new Date(data)) + '';
}
},
{ "mDataProp": "Overall %", sClass: "tdData" },
{ "mDataProp": "Hourly +/-3%", sClass: "tdData" },
{ "mDataProp": "Category +/-3%", sClass: "tdData" },
{ "mDataProp": "CERTIFIED", sClass: "tdData" },
{ "mDataProp": "File Name", sClass: "tdData",
"mRender": function (data, type, full) {
return '' + data + '';
}
}
,
{ "mDataProp": "Validated Date" }
],
"aoColumnDefs": [{ "bVisible": false, "aTargets": [8] },
{ "iDataSort": 8, "aTargets": [2]}],
"bDestroy": true
});
$('#tblUploadHistory').show();
$("#divUploads").show();
setTimeout(function () {
Table.css('width', '100%');
Table.fnAdjustColumnSizing();
}, 10);
}
Facility Name
Submitted Date
Submitted By
Validated Date
Overall %
Hourly +/- 3
Category +/- 3%
Certified
File Uploaded
SortValidatedDate
Thank you very much for your help.
Best regards,
Ali
This discussion has been closed.