Search code examples
angulartypescriptprimengprimeng-datatable

PrimeNG p-dataView with not repeating FieldSet


I am using p-dataView and I would like to use p-fieldset depending on the application type and I would like to find a way for the fieldset not to be repeated. Below is just one case, I will ending up with multiple fieldsSet. Not sure what will be the most efficient way to do this? Basically, I am trying to group certain rows to gather under one fieldset.

for example:

<p-dataView [value]="someobject" [paginator]="true" [rows]="20">

    <ng-template let-prev let-rowIndexValue="rowIndex" pTemplate="listItem">

        <div class="container">
            <div class="row">
                <p-fieldset class="fieldset-auto-width" *ngIf="prev.app_type == 10">
                <p-header style="width:30px">Apps</p-header>
                    <div class="col-md-3">
                        <input type="checkbox" id="cbPreviewID" checked name="cbxPreview" (click)="togglePreviewApp($event,rowIndexValue)" style="margin-right:5px;margin-bottom:10px;margin-left:5px; margin-top:10px" [value]='prev.app_id'> {{prev.app_name}}
                    </div>

                    <div *ngIf="prev.roles.length>1" class="col-md-3" style="margin-right:5px;margin-bottom:10px;margin-left:5px; margin-top:10px">

                    <b>Role:</b> 
                    <select name="role" (ngModelChange)="selectedPreviewAppRole($event,rowIndexValue)" class="dropdown" style="width:85%" required [(ngModel)]="prev.seletedAppRoleID">
                        <option class="dropdown-item" value="" selected>Select</option>
                        <option class="dropdown-item" *ngFor='let role of prev.roles' [ngValue]="role.app_role_id">
                            {{role.app_role_name}}
                        </option>
                    </select>

                </p-fieldset>
            </div>  
        </div>                      
    </ng-template>                      
</p-dataView>

for example test 1 & 2 should be under 1 field set called because their(prev.app_type == 10")

Now I get : enter image description here

Looking for: enter image description here


Solution

  • enter image description hereTried including p-fieldset inside p-dataview. It's working as expected. might be issue with *ngIf condition.

    Component:

    cars = [{
        id: 1,
        items: [{
          name: 'car1',
          description: 'this is car1 description'
        },{
          name: 'car2',
          description: 'this is car2 description'
        },{
          name: 'car3',
          description: 'this is car3 description'
        },{
          name: 'car4',
          description: 'this is car4 description'
        },{
          name: 'car5',
          description: 'this is car5 description'
        }]
    

    }];

    Template:

    <p-dataView [value]="cars" [paginator]="true" [rows]="5">
      <p-header>List of Cars</p-header>
      <p-footer>Choose from the list.</p-footer>
      <ng-template let-car pTemplate="listItem">
          <p-fieldset legend="Header" *ngIf="car.id === 1" [toggleable]="true">
              <div *ngFor="let _car of car.items">
                  {{_car.name}} - {{_car.description}}
              </div>
          </p-fieldset>
      </ng-template>
    </p-dataView>
    

    Refer the attached screenshot.