primeng icon indicating copy to clipboard operation
primeng copied to clipboard

TurboTable column with number and thousand separator

Open jsilveira2 opened this issue 8 years ago • 6 comments

Hi everyone, I have a question about columns with numbers and separators from thousands, I did not find anything on the internet or the documentation talking about the subject and I would like to raise this doubt and also check if in case it can not be created something like this in future versions.

My question is this: I have a p-table with columns that have number values, and I need them to appear on the screen with the thousands house separator. Example:

  • Value: 1500700
  • Value that should appear on screen: 1,500,700

Is there any primeng turbotable tool that does this? Thank you very much in advance. Sorry for my bad english.

My packages information: "@angular/cli": "^6.2.3" "primeng": "^6.1.4"

jsilveira2 avatar Oct 01 '18 14:10 jsilveira2

This can be accomplished using the DecimalPipe provided by Angular https://angular.io/api/common/DecimalPipe

data = { value: 1500700 }
<p-table [value]="data">
    <ng-template pTemplate="header">
        <tr>
            <th>Value</th>
        </tr>
    </ng-template>
    <ng-template pTemplate="body" let-data>
        <tr>
            <td>{{ data.value | number }}</td>
        </tr>
    </ng-template>
</p-table>

jayscheidt avatar Oct 16 '18 22:10 jayscheidt

Hi, thanks for the reply.

I understood your suggestion, but how do you apply it when you have columns and dynamic values.

Example:

<p-table [columns]="cols" [value]="data" selectionMode="single" [(selection)]="selectedRow" [responsive]="true" [rows]="10" [paginator]="true">
   <ng-template pTemplate="header" let-columns>
        <tr>
            <th *ngFor="let col of columns" [pSortableColumn]="col.field">
               {{col.header}}
               <p-sortIcon [field]="col.field" ariaLabel="Activate to sort" 
                   ariaLabelDesc="Activate to sort in descending order" 
                   ariaLabelAsc="Activate to sort in ascending order"></p-sortIcon>
            </th>
        </tr>
    </ng-template>

    <ng-template pTemplate="body" let-rowData let-columns="columns">
       <tr [pSelectableRow]="rowData">
          <td *ngFor="let col of columns" class="ui-resizable-column">
             {{rowData[col.field]}}
          </td>
       </tr>
    </ng-template>
</p-table>

cols: any[] = [
   { field: 'ibge', header: 'IBGE' },
   { field: 'desc', header: 'Descrição' },
   { field: 'macroRegiao', header: 'Macroregião' },
   { field: 'populacao', header: 'População' }
 ];
data: any[] = [
   { ibge: 4202404, desc: 'Blumenau', macroRegiao: 'Vale do Itajaí', populacao: 352460 },
   { ibge: 4204202, desc: 'Chapecó', macroRegiao: 'Oeste', populacao: 216578 },
   { ibge: 4205407, desc: 'Florianópolis', macroRegiao: 'Sul', populacao: 499777 },
   { ibge: 4209102, desc: 'Joinville', macroRegiao: 'Norte', populacao: 583144 },
   { ibge: 4208203, desc: 'Itajaí', macroRegiao: 'Vale do Itajaí', populacao: 215895 }
 ];

Sorry for my bad english.

jsilveira2 avatar Oct 17 '18 13:10 jsilveira2

You just need to pipe your data in the HTML. All columns and data can still be dynamic, you just need to pass the value to render. From your example above: <ng-template pTemplate="body" let-rowData let-columns="columns"> <tr [pSelectableRow]="rowData"> <td *ngFor="let col of columns" class="ui-resizable-column"> {{rowData[col.field] | number}} <-------- here is the pipe </td> </tr> </ng-template>

cuneytcalishkan avatar Mar 19 '19 22:03 cuneytcalishkan

Thats it! Thanks for help @cuneytcalishkan.

jsilveira2 avatar Mar 20 '19 11:03 jsilveira2

Better fit for a forum discussion.

cagataycivici avatar Sep 05 '19 13:09 cagataycivici

not understand. How to print column number in primng table as angular index?

romaricsylvain avatar May 05 '21 09:05 romaricsylvain