I get back from the server an object containing an array of columns with their definitions and an array of rows. I would like to iterate over the columns and rows as I build my HTML table and format the cells according to the column type returned using a "format" pipe.
For example
WS Response:
{
"columns" [{"precision":10,"name":"PAGES","typeName":"INTEGER","scale":0...,
"rows":[{"PAGES":6531....}, [{"PAGES":6531....}]
}
HTML fragment:
<tr *ngFor="let row of invoices?.rows">
<td *ngFor="let column of invoices?.columns>
{{row[column.name] | format : column}}
</td>
</tr>
Is there any way my "format" pipe can just act a a delegator to the correct built-in pipe (where one exits), depending on the type of the column? I don't want to have to re-implement DecimalPipe, DatePipe, etc. etc.
Yes you can call pipes - just instatiate them and call transform
:
transform(cell: any, column: any): any {
if (column.typeName === "INTEGER") {
let pipe = new DecimalPipe();
return pipe.transform(cell, "1.0-0");
}
// more here ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With