Table is displaying in reverse alphabetical order. How do I get it in a-z order?
Table is displaying in reverse alphabetical order. How do I get it in a-z order?

The JSON table is not in order, but is displayed in reverse. The table originally had a first column showing 'Yes' or 'No' and was displaying in that order. I have removed that column. The page is not yet live, so I cannot link it here. Below is the script that drives the table.
<script>
$(document).ready(function() {
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"my-currency-pre": function(a) {
return parseFloat(a.replace(/[ $,]/gi, ''));
},
"my-currency-asc": function(a,b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"my-currency-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
$('#example').DataTable( {
"ajax": '/careerconnections/data/DataTables/demand_occupations_list_2020.txt',
"order": [0],
"lengthMenu": [ 10, 25, 50, 75, 100 ],
"aoColumnDefs": [
{"sType": "my-currency", "aTargets": [3,4,5]}
]
} );
} );
</script>
First few lines of the JSON
{
"data":[
["Compliance Officers, Except Agriculture, Construction, Health and Safety, and Transportation","12,340","$83,205","600","970","Bachelor's degree" ],
["Cost Estimators","5,270","$75,339","650","610","Bachelor's degree" ],
["Human Resources Specialists","17,510","$75,357","1,250","1,800","Bachelor's degree" ],
["Logisticians","7,530","$84,241","750","790","Bachelor's degree" ],
["Management Analysts","14,340","$105,676","1,950","1,770","Bachelor's degree" ],
["Meeting, Convention, and Event Planners","3,060","$65,953","550","490","Bachelor's degree" ],
["Market Research Analysts and Marketing Specialists","19,330","$87,212","4,050","2,470","Bachelor's degree" ],
On the page, the first item showing in the table is Welders, Cutters, Solderers, and Brazers.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I don't really understand the question; but why don't you just apply the initial order of your choice as explained in the docs?
https://datatables.net/reference/option/order
I should have mentioned, I am not a coder. I maintain and update this website, but the coder was hired, and I cannot pay for edits.
So, if I edited the order line to
should that fix it?
Also, page is now live.
https://careerconnections.nj.gov/careerconnections/prepare/skills/demand/demand_occupations_list.shtml
Yes - if you want default sorting to be by your first column, A-Z.
Column numbering begins with 0, left to right.
The
order
docs state this:You should have
"order": [[0, 'asc']],
instead. Also the docs state the default value is[[0, 'asc']]
so the first column should be sorted ascending by default without the need of"order": [[0, 'asc']],
.Kevin
kthorngren, the original code was
and this produced the reverse order. I changed it to
as tangerine suggested and it is now displaying correctly. Thank you for your answer, I will change it as you said and see if it still works. Although I am not a coder, I do try to learn.
Kevin is correct, my mistake.
I changed it and it is working.
Thank you both very much.