How to add table column field to array index

UI Components for Angular
Post Reply
Aravindaful
Posts: 1
Joined: 28 Jul 2019, 14:07

28 Jul 2019, 14:15

Hi,
I want to create table columns dynamically and columns values getting from arrays.

Please help me to solve this issue

Code: Select all

 <p-table [columns]="columns" [value]="uersSurveyAnswers">
                            <ng-template pTemplate="header"  let-columns>
                                <tr>
                                    <th>
                                        Respondent Name
                                    </th>
                                    <th *ngFor="let col of columns">
                                        {{col.header}}
                                    </th>
                                </tr>
                            </ng-template>
                            <ng-template pTemplate="body" let-surveyAnswer let-columns="columns">
                                <tr>
                                    <td>{{surveyAnswer.userEmail}}</td>
                                     <td>{{surveyAnswer.qustns[0].ansrs[0]}}</td>
                                    <td *ngFor="let col of columns" >
                                              {{col.field }}
                                        </td>
                                </tr>
                            </ng-template>
                        </p-table>
here is my array

Code: Select all

uersSurveyAnswers: any = [
    {
      userEmail: 'amara@gmail.com',
      qustns: [
        {
          qNo: 1,
          ansrs: ['1']
        },
        {
          qNo: 2,
          ansrs: ['1', '0', '1', '1']
        },
        {
          qNo: 5,
          ansrs: ['2']
        },
        {
          qNo: 6,
          ansrs: ['0', '1', '1', '0']
        }
      ]
    }];
I opened stackoverflow question.here is the link
https://stackoverflow.com/questions/572 ... -angular-8

please help me to solve this issue

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests