I have the following function executed as my datatable initiates. It grabs all the keywords in the column "keywords", counts them, and then lists them.
What I want to know is how can I sort the final counts
variable by value before I pass it to the html.
function getTags(table) {
var data = $('#mytable').DataTable().rows({search: 'applied'}).data();
var keys=[]; // Get keywords
for(var i=0;i<data.length;i++){
keys.push(data[i].keyword)
}
var keyStr = keys.toString().split(","); // Split keywords
var keyStr = keyStr.filter(function(n){ return n != "" }); // Filter empty
var counts = {}; // Count unique
for (var i = 0; i < keyStr.length; i++) {
counts[keyStr[i]] = 1 + (counts[keyStr[i]] || 0);
}
$.each(counts, function (key,value) { // Print list
$("#tags ul").append("<li>" + value + key + "</li>");
})