I have this HTML table
<table id="table">
<thead>
<tr>
<td>Nº</td>
<td>NOMBRE</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Andrea</td>
</tr>
<tr>
<td>2</td>
<td>Gabriela</td>
</tr>
<tr>
<td>3</td>
<td>Gabriela</td>
</tr>
<tr>
<td>4</td>
<td>Alba</td>
</tr>
<tr>
<td>5</td>
<td>Jose</td>
</tr>
<tr>
<td>6</td>
<td>Luis</td>
</tr>
<tr>
<td>7</td>
<td>Alba</td>
</tr>
</tbody>
</table>
And this script counts the table-rows with the ID "total__registros"
function totalregistros(){
var TotalRegistros= document.getElementById("table").rows.length;
document.getElementById("total__registros").value = "Registros: " + (TotalRegistros-1);
}
window.onload=totalregistros();
And the result is: "Registros: 7"
How to make the script count unique values only, based on the "NOMBRE" field, that should say, the result is: "Registros: 5"
I have this SQL statement that does not work in JS:
SELECT COUNT(DISTINCT NOMBRE) FROM usuarios
4
Answers
querySelectorAll
to select all secondtd
‘s in atr
of the
tbody
.array.prototype.length
to count the numbers of unique names:You can create a
Set
from all the names, then take itssize
.Not going to get into formatting since you can probably figure that part out. You would use something like this and put it in a collection wherever you build billCollection you can add this to it, then you can reference that collection in your html
ClearCollect(colbillCount,ShowColumns( AddColumns( GroupBy(billcollection, "NumeralDenomination", "ByDenomination"), "DenominationCount", CountRows(ByDenomination) ), "NumeralDenomination", "DenominationCount" ))
Please use these one in tobody and tr tag
ForAll(colBillCount,colBillCount.NumberalDenomination
colBillCount.DenominationCount
thanks
To get values easily, you need to change from td tags inside thead tag to th tag.