SHARE
TWEET

Untitled

a guest Jun 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let headers = document.querySelectorAll('.percentage_header');
  2. headers.forEach(header => header.addEventListener('click', sortAll));
  3.  
  4. var sortDir = 1;
  5.  
  6. var mainTable = document.querySelector('.main_results_table');
  7. var mainTableRows =  Array.from(mainTable.querySelectorAll('.main_table_rows'));
  8.  
  9. var individualRowsFromMainTableRows = document.querySelectorAll('.individual_rows');
  10.  
  11. function sortAll() {
  12.  
  13.   individualRowsFromMainTableRows.forEach(function(row) {
  14.     individualStudentResults = Array.from(individualRowsFromMainTableRows.querySelectorAll(".single_test_row"));
  15.     individualStudentResults.sort(function(a,b){
  16.       if(a.querySelector(".percentage_value") == undefined) return 1;
  17.       if(b.querySelector(".percentage_value") == undefined) return 0;
  18.       return sortDir == -1 ? (a.querySelector(".percentage_value").textContent > b.querySelector(".percentage_value").textContent) : (a.querySelector(".percentage_value").textContent < b.querySelector(".percentage_value").textContent);
  19.       // return parseFloat(a.querySelector(".theory_percentage_value").textContent) - parseFloat(b.querySelector(".theory_percentage_value").textContent) * sortDir;
  20.     })
  21.     individualStudentResults.forEach(individualStudentResult => individualRowsFromMainTableRows.appendChild(individualStudentResult));
  22.   })  
  23.  
  24.   mainTableRows.sort((a, b) => sortDir * (getVal(a) - getVal(b)));            
  25.   mainTableRows.forEach(mainTableRow => mainTable.appendChild(mainTableRow));
  26.   sortDir = -sortDir
  27. }
  28.  
  29. function getVal(rw) {
  30.     var a = parseFloat(rw.querySelector('.individual_rows .single_test_row .percentage_value').textContent);
  31.     return a ? a : 0;
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top