How to sort a javascript table (ascending or descending) which is the result of some SQL operated table?
<p>I had created a table using JavaScript in which there are three columns Event ID, Events and Total Count. Now I have to sort the third column i.e total count in descending order. I have been looking online how to sort it. I know how to sort tables for standard HTML table <code>("order": [[ 2, "desc" ]])</code> but this table is formed using JavaScript, so I am confuse. I could use a loop for creating a table backward i.e  <code>for(var i=to; i&gt;=from; i--)</code> but my result JS table is the result from the table which is generated from SQL in which "Events" are not order by ascending or descending. In other words, I am creating this JavaScript table from the SQL generated table. Below is the code I am working on: </p>

<pre><code>&lt;script&gt;
    $(function() {
        CreateTable(GetSum('#displaytable'));
    });

    function GetSum(tableIdWithHash) {
        var Sum = [];
        var EventIds = [];
        var EventName = [];
        var Data = [];

        $(tableIdWithHash).find('.eventCounts').each(function(i){
        var Counte = $(this).html();
        var Ide = $(this).siblings('.Idevent').html();
        var eName = $(this).siblings('.eventNames').html();

            allSum.sort(function(a,b){
      if(a.eCount &gt; b.eCount){
         return 1;
      } else if (a.eCount &lt; b.eCount){
         return -1;
      } else{
         return 0;
      }
    }); 
        if (EventIds.indexOf(Ide) === -1) {
            EventIds.push(Ide);
            EventName.push(eName);
        }

        var index = EventIds.indexOf(Ide);
        if (Sum[index] == undefined) {
            Sum[index] = Number(Counte);
        }
        else {
            Sum[index] += Number(Counte);
        }
        });

        Data.push(EventIds);
        Data.push(EventName);
        Data.push(Sum);
        //"order": [[ 2, "desc" ]]
        return Data;
    }       
&lt;/script&gt;
</code></pre>