How to add custom tr to datatable which is created in my vanilla javascript ?
How to add custom tr to datatable which is created in my vanilla javascript ?
abdul2004
Posts: 1Questions: 1Answers: 0
const tableGainers = document.getElementById('table-market');
for (const gainers of obj) {
const tr = document.createElement('tr');
const contentArr = `<td><img src=${gainers.urlLogo} alt="logo_coin" class="logo-coin-tb"/>${gainers.symbol}</td>
<td>${gainers.lastPrice}</td>
${gainers.priceChangePercent > 0 ? `<td style="color: green"> ${gainers.priceChangePercent}% </td>` : `<td style="color: red"> ${gainers.priceChangePercent}% </td>`}
<td>${gainers.volume}</td>
<td><button type="button" class="btn-go-trade">Go Trading</button></td>`;
tr.innerHTML = contentArr;
tr.className = 'tableRow';
tr.id = 'tblmarket-row';
tableGainers.appendChild(tr);
}
obj is my json array
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
I'm not clear on what your question is here I'm afraid?
Allan
Oh - just a minute - are you asking how to add that
tr
to a DataTable? Userow.add()
it will accept atr
as long as it is in the structure configured for the table (i.e. correct number of columns, etc).Personally I'd just use
row.add()
with the raw data and use renderers in the DataTable to format it as you need.Allan