static/js/datable.js
/**
 * Populate data table by data.
 * @function fillDataTable
 * @param {Object} mo - main object
 * @param {string} [title] - title of data table (use current if omitted)
 * @param {number} [n=100] - number of contigs to show per page
 * @param {number} [p=0] - page number (starting from 0)
 */
Populate data table by data.
Populate data table by data .
function fillDataTable(mo, title, n, p) {
  const data = mo.data,
        cols = mo.cols;
  const tabled = mo.tabled;
  let N = tabled.length;
  if (!N) return;
  n = n || 100;
  p = p || 0;
  const start = n * p;
  const length = Math.min(n, N - start);
  if (length < 1) return;
  const end = start + length;
  const table = byId('data-table');
  if (!title) title = table.getAttribute('data-title');
  else table.setAttribute('data-title', title);
  const tbody = table.tBodies[0];
  tbody.innerHTML = '';
  const names = cols.names,
        types = cols.types;
  const m = names.length;
  let idx, j, row, type, cell;
  for (let i = start; i < end; i++) {
    idx = tabled[i];
    row = tbody.insertRow(-1);
    for (j = 0; j < m; j++) {
      type = types[j];
      if (type.endsWith('wt')) continue;
      cell = row.insertCell(-1);
      cell.innerHTML = value2Str(data[j][idx], type);
    }
  }
  const P = Math.ceil(N / n);
  table.setAttribute('data-nctg', n);
  table.setAttribute('data-ipage', p);
  table.setAttribute('data-npage', P);
  byId('data-title-span').innerHTML =
    `${title} (${start + 1} to ${end}) of ${N}`;
  const text = byId('data-page-txt');
  text.value = p + 1;
  text.title = `Page ${p + 1} of ${P}`;
  byId('data-prev-btn').disabled = (p === 0);
  byId('data-next-btn').disabled = (p === P - 1);
}
function fillDataTable ( mo , title , n , p ) { const data = mo . data , cols = mo . cols ; const tabled = mo . tabled ; let N = tabled . length ; if ( ! N ) return ; n = n || 100 ; p = p || 0 ; const start = n * p ; const length = Math . min ( n , N - start ) ; if ( length < 1 ) return ; const end = start + length ; const table = byId ( 'data-table' ) ; if ( ! title ) title = table . getAttribute ( 'data-title' ) ; else table . setAttribute ( 'data-title' , title ) ; const tbody = table . tBodies [ 0 ] ; tbody . innerHTML = '' ; const names = cols . names , types = cols . types ; const m = names . length ; let idx , j , row , type , cell ; for ( let i = start ; i < end ; i ++ ) { idx = tabled [ i ] ; row = tbody . insertRow ( - 1 ) ; for ( j = 0 ; j < m ; j ++ ) { type = types [ j ] ; if ( type . endsWith ( 'wt' ) ) continue ; cell = row . insertCell ( - 1 ) ; cell . innerHTML = value2Str ( data [ j ] [ idx ] , type ) ; } } const P = Math . ceil ( N / n ) ; table . setAttribute ( 'data-nctg' , n ) ; table . setAttribute ( 'data-ipage' , p ) ; table . setAttribute ( 'data-npage' , P ) ; byId ( 'data-title-span' ) . innerHTML = ` ${ title } ${ start + 1 } ${ end } ${ N } ` ; const text = byId ( 'data-page-txt' ) ; text . value = p + 1 ; text . title = ` ${ p + 1 } ${ P } ` ; byId ( 'data-prev-btn' ) . disabled = ( p === 0 ) ; byId ( 'data-next-btn' ) . disabled = ( p === P - 1 ) ; }
Populate data table by data.
Populate data table by data .
// determine range of contigs to show // clear existing content // get columns to show // populate table