0

I am using angular 7 with primeng

In one of my primeng table, I am getting one of column of table as array

permissions: ["api-search-miscellaneous", "api-show-miscellaneous", "api-updatestatus-miscellaneous",…]
0: "api-search-miscellaneous"
1: "api-show-miscellaneous"
2: "api-updatestatus-miscellaneous"
3: "api-delete-miscellaneous"
4: "api-add-miscellaneous"
5: "api-showall-miscellaneous"
6: "api-update-miscellaneous"

Now primeng showing that column with comma separated , How can i show that array elements one after other in different line in one row only .

These are my columns , here permission is in form of array , which I am showing as group on my web page .ts file code

 this.cols = [
            {
                field: 'name',
                header: this.getLocalTranslation(
                    'Features.gridLabel.featureGroup',
                ),
            },
            {
                field: 'permissions',
                header: this.getLocalTranslation(
                    'Features.gridLabel.functionalities',
                ),
            },
        ];

.html file code

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

enter image description here

Shilpi Jaiswal
  • 1,178
  • 2
  • 12
  • 27
  • isn't it possible to just use standard html and/or css3: something like this: https://stackoverflow.com/questions/10937218/how-to-show-multiline-text-in-a-table-cell – jcuypers May 16 '19 at 06:58

1 Answers1

0

I got the solution for my problem

I changed my .ts code to this one , I used Angular slice pipe and iterated through array.

    <ng-template pTemplate="body" let-rowData let-columns="columns">
        <tr [pSelectableRow]="rowData">
            <td *ngFor="let col of columns">
                <div
                    *ngIf="
                        col.field == 'permissions';
                        then content;
                        else other_content
                    "
                ></div>
                <ng-template #content>
                    <li *ngFor="let i of rowData[col.field] | slice: 0:i">
                        {{ i }}
                    </li></ng-template
                >
                <ng-template #other_content>{{
                    rowData[col.field]
                }}</ng-template>
            </td>
        </tr>
    </ng-template>
Shilpi Jaiswal
  • 1,178
  • 2
  • 12
  • 27