User:Glorat/BoglebotTable

Boglebot Table Widget User Guide
The following user guide included here is authored at User:Glorat/BoglebotTableGuide

Example
Global Equity ETFs for non-US

function generateBogleBotTable(data, elem) { var Html = mw.html; const {rows, fields, headers} = data; // Mandatory name field at the start const idx = fields.findIndex(x => x === 'name'); if (idx>0) { fields.splice(idx, 1); headers.splice(idx, 1); } headers.unshift('Name'); var ths = headers.map(function(h) {return Html.element('th', {class:'headerSort', tabIndex:'0', role: 'columnheader button', title: 'Sort ascending'}, h);}); var trs = rows.map(function(row) {   var cells = [];    cells.push(Html.element('a', {href:'https://www.boglebot.com/quotesdb/' + row.id, class: 'external text'}, row.name));    fields.forEach(function(path) { cells.push(row[path]) });

var tds = cells.map(function(col){return ' ' + col + ' '}); return ' ' + tds.join('') + ' ' }); // Relocate the original link to a nice place  trs.push(` Source: ${elem.outerHTML}  `);

var tbody = Html.element('tbody',{}, new Html.Raw(trs.join(''))); var thead = ' ' + ths.join('') + ' '; var table = Html.element('table', {class:'dyntable wikitable sortable jquery-tablesorter mw-datatable'}, new Html.Raw(thead + tbody));

return table; }

async function doIt { const functionUrl = 'https://asia-northeast1-gainstrack.cloudfunctions.net/fastQuoteSourceTableQuery'; $('a[href^="https://www.boglebot.com/assetdb?args="]').each(function(index, elem) {   const href = elem.href;    const link = href.replace('https://www.boglebot.com/assetdb', functionUrl);    $.getJSON(link, function(data) { const html = generateBogleBotTable(data, elem); const parent = $(elem).parent; $(elem).replaceWith(html); $('table', parent).tablesorter; }) });

}

if (!window.bogleBotTableInit) { window.addEventListener('load', function {   // mw.loader.using( ['jquery.tablesorter'] ).then( function  { setTimeout(function {     console.log('All assets are loaded');      doIt;    },100 ); }); window.bogleBotTableInit = true; }