Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                  <table class="functionableTable" id="covid19TableWithSort">

            <thead>

                <tr class="titleRow">
                    <th id="tableTitle">CANADIAN COVID CASES (Reported on April 23, 2021)</th>
                </tr>
                <tr class="headings">
                    <th class="colHeader">Province &nbsp; <button class="sort" id="provSort" onclick="sortTableByColNum('1')"><i class="down-arrow" id="provSortIcon">&#9660;</i></button> <p id="provSortValue" hidden>0</p></th>
                    <th class="colHeader">Population <button class="sort" id="popSort"  onclick="sortTableByColNum('2')"><i class="down-arrow" id="popSortIcon">&#9660;</i></button><p id="popSortValue" hidden>0</p></th>
                    <th class="colHeader">Cases <button class="sort" id="casesSort"  onclick="sortTableByColNum('3')"><i class="down-arrow" id="casesSortIcon">&#9660;</i></button><p id="casesSortValue" hidden>0</p></th>
                    <th class="colHeader">Recoveries <button class="sort" id="recoveriesSort"  onclick="sortTableByColNum('4')"><i class="down-arrow" id="recoveriesSortIcon">&#9660;</i></button><p id="recoveriesSortValue" hidden>0</p></th>
                    <th class="colHeader">Deaths <button class="sort" id="deathsSort"  onclick="sortTableByColNum('5')"><i class="down-arrow" id="deathsSortIcon">&#9660;</i></button><p id="deathsSortValue" hidden>0</p></th>   
                    <th class="colHeader">Active <button class="sort" id="activeSort"  onclick="sortTableByColNum('6')"><i class="down-arrow" id="activeSortIcon">&#9660;</i></button><p id="activeSortValue" hidden>0</p></th>
                </tr>
                
            </thead>

            <tbody>

                <tr>
                    <td>British Columbia</td>
                    <td>5,145,851</td>
                    <td>122,757</td>
                    <td>112,235</td>
                    <td>1,550</td>
                    <td>8,733</td>
                </tr>

                <tr>
                    <td>Alberta</td>
                    <td>4,428,112</td>
                    <td>177,087</td>
                    <td>155,851</td>
                    <td>2,054</td>
                    <td>19,182</td>
                </tr>

                <tr>
                    <td>Saskatchewan</td>
                    <td>1,177,884</td>
                    <td>39,137</td>
                    <td>36,162</td>
                    <td>470</td>
                    <td>2,505</td>
                </tr>

                <tr>
                    <td>Manitoba</td>
                    <td>1,379,584</td>
                    <td>37,069</td>
                    <td>34,366</td>
                    <td>967</td>
                    <td>1,739</td>
                </tr>

                <tr>
                    <td>Ontario</td>
                    <td>14,733,119</td>
                    <td>437,310</td>
                    <td>387,712</td>
                    <td>7,863</td>
                    <td>41,735</td>
                </tr>

                <tr>
                    <td>New Brunswick</td>
                    <td>781,315</td>
                    <td>1,823</td>
                    <td>1,642</td>
                    <td>34</td>
                    <td>146</td>
                </tr>
                
                <tr>
                    <td>Prince Edward Island</td>
                    <td>159,713</td>
                    <td>175</td>
                    <td>164</td>
                    <td>0</td>
                    <td>11</td>
                </tr>

                <tr>
                    <td>Nova Scotia</td>
                    <td>979,115</td>
                    <td>1,938</td>
                    <td>1,721</td>
                    <td>67</td>
                    <td>150</td>
                </tr>

                <tr>
                    <td>Newfoundland &amp; Labrador</td>
                    <td>520,998</td>
                    <td>1,053</td>
                    <td>1,020</td>
                    <td>6</td>
                    <td>23</td>
                </tr>

                <tr>
                    <td>Yukon</td>
                    <td>42,176</td>
                    <td>80</td>
                    <td>75</td>
                    <td>1</td>
                    <td>4</td>
                </tr>

                <tr>
                    <td>Northwest Territories</td>
                    <td>45,074</td>
                    <td>46</td>
                    <td>43</td>
                    <td>0</td>
                    <td>3</td>
                </tr>

                <tr>
                    <td>Nunavut</td>
                    <td>39,285</td>
                    <td>441</td>
                    <td>400</td>
                    <td>4</td>
                    <td>37</td>
                </tr>

            </tbody>

        </table>
        
        <div class="sectionFooter">

            <p id="reference">Data obtained from Wikipedia: <a href="https://en.wikipedia.org/wiki/Template:COVID-19_pandemic_data/Canada_medical_cases_by_province">COVID-19 Data</a> </p>            
        </div>

              
            
!

CSS

              
                
table{
  line-height: 35px;  

  border: 2px solid black;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;

  margin: 0 auto;     

}

tbody{
  font-family: "Helvetica-Neue", Helvetica, Arial;
  font-size: 1.1em;
}


tbody tr:nth-child(odd){
  background-color: #ebedee;
  color: #000000;
}

tbody tr:nth-child(even){
  background-color: #d3d2d2;
  color: #000000;
}

tbody tr td:first-child{
  text-align: left;
  padding-left: 10px;
}

tbody tr{
  opacity: 0.8;  
}

tbody tr:hover{
  font-weight: bold;  
  /*text-shadow: 1px 1px #cac9c9;*/
  opacity: 1;    
}

tbody tr td:nth-child(2), tbody tr td:nth-child(3), tbody tr td:nth-child(4), tbody tr td:nth-child(5), tbody tr td:nth-child(6){
  text-align: center;
} 
.sectionFooter p{    
  font-family: Helvetica, Arial, sans-serif;  
  font-size: 1em;
  text-align: center;
}

.headings{
  background-image: linear-gradient(180deg, #526bfa, #0522c5);
  color: #ffffff; 
  font-family: "Helvertica Neue", Arial, Helvetica, sans-serif;
  font-weight: bold; 
  font-size: 1.2em;  
  margin: 2% 0 3% 0;
}

.headings th:nth-child(1){ 
  text-align: left;
  padding: 2px 0 2px 10px;
}

.tr {
  margin-left: 5%;
  margin-right: 5%;
}

.headings button{
  margin-bottom: 10px;
}

#tableTitle{
  font-size: 1.3em;
  padding: 5px 0 5px 10px;    
}
              
            
!

JS

              
                var colSortValue; 
var colToSkip;

var tableDataArray;

var table, rows, continueSort, switchRow,  curRow, nextRow, dirToSort, counter;

var numberOrString;

function resetIcons(){
  // Changes the icons back to default (chevron down icon

  var test;

  var element;

  var iconsToChange = $("i");

  console.log("coltoskip: " + colToSkip)

  for(i = 0; i < iconsToChange.length; i++){

    test = iconsToChange[i].id;

    if(test != colToSkip)
    {

      $("#" + test).removeClass("fa-chevron-up").addClass("fa-chevron-down");

    }

  }

}

function getValues(){
  // Gets the table values

  table = document.getElementById("covid19TableWithSort");

  rows = table.rows;

}

function sortTableByColNum(intColNum){
  /* Changes the curremt icon on the row header for the selected row to sort and changes the icons for the othe columms back to default
     Sets the current search value for the search direction - 0 = down, 1 = up
     Starts the search procedure */   

    var element;
       
    switch(parseInt(intColNum)){
       
      case 1:

        colToSkip = "provSortIcon";

        element = $("#provSortValue");
                   
        colSortValue = element.html();
       
        if(colSortValue == 0){
                         
          $("#provSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");                       
               
        }
            
        if(colSortValue == 1){
                                       
          $("#provSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");                                  

        }
            
        break;
        
        case 2:

          colToSkip = "popSortIcon";

          element = $("#popSortValue");
                   
          colSortValue = element.html();
               
        if(colSortValue == 0){
                             
          $("#popSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");            
                 
        }
              
        if(colSortValue == 1){
                                          
          $("#popSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");                                  
  
        }
         
        break;

        case 3:

          colToSkip = "casesSortIcon";

          element = $("#casesSortValue");
                   
          colSortValue = element.html();
  
          if(colSortValue == 0){
                                              
            $("#casesSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");            
                 
          }
              
          if(colSortValue == 1){
                             
            $("#casesSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");                                  
  
          }
           
          break;

          case 4:

          colToSkip = "recoveriesSortIcon";

          element = $("#recoveriesSortValue");
                   
          colSortValue = element.html();
  
          if(colSortValue == 0){
                                              
            $("#recoveriesSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");            
                
          }
              
          if(colSortValue == 1){
                          
            $("#recoveriesSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");                                  

          }                            

          break;

          case 5:

            colToSkip = "deathsSortIcon";

            element = $("#deathsSortValue");
                   
            colSortValue = element.html();
  
          if(colSortValue == 0){
  
            $("#deathsSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");            
                 
          }
              
           if(colSortValue == 1){
  
            $("#deathsSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");                                  
  
          }                        

          break;

          case 6:

            colToSkip = "activeSortIcon";

            element = $("#activeSortValue");
                   
            colSortValue = element.html();
  
            if(colSortValue == 0){
                                             
               $("#activeSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");            
                 
            }
              
            if(colSortValue == 1){
                                             
              $("#activeSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");                                  
  
            }            
           
            break;
                        
    }

    if(colSortValue == 0){      
      
      dirToSort = "down";
                  
      element.html(1);    

    }

    if(colSortValue == 1){

      dirToSort = "up";

      element.html(0);

    }
  
    resetIcons();  
    
    sortTable(intColNum);

    /*$(this).find($(".fa")).removeClass('fa-chevron-down').addClass('fa-chevron-up');*/

}

function sortTable(colNum){

    var numberOfPasses;

    var columnToSortBy = colNum - 1;   

    var value1, value2;

    getValues();

    continueSort = true;

    counter = rows.length;
    
    while(continueSort){

      for(numberOfPasses = 0; numberOfPasses < counter; numberOfPasses++){

        for(i = 2; i < rows.length - 1; i++){

          if(colNum > 1){

            numToCompare1 = rows[i].getElementsByTagName("td")[columnToSortBy];     
        
            curRow = parseInt(numToCompare1.innerHTML.replace(/,/g, ''));
    
            numToCompare2 = rows[i + 1].getElementsByTagName("td")[columnToSortBy];
    
            nextRow = parseInt(numToCompare2.innerHTML.replace(/,/g, ''));

            value1 = curRow;
            value2 = nextRow;

          }
          else{

            curRow = rows[i].getElementsByTagName("td")[columnToSortBy];

            nextRow = rows[i + 1].getElementsByTagName("td")[columnToSortBy];

            value1 = curRow.innerHTML.toUpperCase();
            value2 = nextRow.innerHTML.toUpperCase();

          }

          console.log("Value 1: " + value1 + " Value 2: " + value2);

          if(dirToSort == "down"){
            
            if(value1 > value2 ){
                
                rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);            

                continueSort = true;   

            }
            else{

              continueSort = false;

            }           
            
          }

          if(dirToSort == "up"){

            if(value1 < value2){

              rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
             
              continueSort = true;

            }
            else{

              continueSort = false;

            }

          }

        }

      }

    }

  }
              
            
!
999px

Console