static/js/binning.js
/**
 * Sort bin table by clicking header.
 * @function sortBinTable
 * @param {number} idx - index of table column to sort with
 * @description Modified based on:
 * @see {@link https://www.w3schools.com/howto/howto_js_sort_table.asp}
 */
Sort bin table by clicking header.
Sort bin table by clicking header .
function sortBinTable(idx) {
  const table = byId('bin-tbody');
  let switching = true;
  let ascending = false;
  let switchcount = 0;
  let rows, i, a, b, shouldSwitch;
  while (switching) {
    switching = false;
    rows = table.rows;
    for (i = 0; i < (rows.length - 1); i++) {
      shouldSwitch = false;
      a = rows[i].cells[idx].textContent;
      b = rows[i + 1].cells[idx].textContent;
      if (ascending) {
        if (a.localeCompare(b, undefined, {numeric: true}) > 0) {
          shouldSwitch = true;
          break;
        }
      } else {
        if (a.localeCompare(b, undefined, {numeric: true}) < 0) {
          shouldSwitch = true;
          break;
        }
      }
    }
    if (shouldSwitch) {
      rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
      switching = true;
      switchcount ++;
    } else {
      if (switchcount === 0 && !ascending) {
        ascending = true;
        switching = true;
      }
    }
  }
}
function sortBinTable ( idx ) { const table = byId ( 'bin-tbody' ) ; let switching = true ; let ascending = false ; let switchcount = 0 ; let rows , i , a , b , shouldSwitch ; while ( switching ) { switching = false ; rows = table . rows ; for ( i = 0 ; i < ( rows . length - 1 ) ; i ++ ) { shouldSwitch = false ; a = rows [ i ] . cells [ idx ] . textContent ; b = rows [ i + 1 ] . cells [ idx ] . textContent ; if ( ascending ) { if ( a . localeCompare ( b , undefined , { numeric : true } ) > 0 ) { shouldSwitch = true ; break ; } } else { if ( a . localeCompare ( b , undefined , { numeric : true } ) < 0 ) { shouldSwitch = true ; break ; } } } if ( shouldSwitch ) { rows [ i ] . parentNode . insertBefore ( rows [ i + 1 ] , rows [ i ] ) ; switching = true ; switchcount ++ ; } else { if ( switchcount === 0 && ! ascending ) { ascending = true ; switching = true ; } } } }
Sort bin table by clicking header.
Sort bin table by clicking header .