10
votes

I'm adding p-dropdown to a p-table similar to what is seen here: https://www.primefaces.org/primeng/#/table/filter

The p-dropdown is overflowing into the next cell. How can I prevent p-dropdown from flow to the next cell?

I have tried the following:
- adding [style]="{'width':'100%'}" to p-dropdown element
- adding [autoWidth]="true" to the p-dropdown element
- adding max-width to the p-dropdown element

<p-table [columns]="cols" [value]="wfdata" [paginator]="true" [rows]="10">

...

<th *ngFor="let col of cols" [ngSwitch]="col.value">
          <p-dropdown *ngSwitchCase="'invoice_status'" 
                    [options]="statuses" 
                    [autoWidth]="true"
                    [style]="{'width':'100%'}"></p-dropdown>

...

</p-table>
6
just reset the min-width to 0 of .ui-dropdown class will solve the problem 🙂🙂 , check the demo with my answerMuhammed Albarmavi
@mark - You can use the selector p-dropdown .ui-dropdown in your CSS. See this stackblitz.ConnorsFan

6 Answers

11
votes

inside the p-dropdown component there is a class .ui-dropdown this set the min-width to fixed values 12.5em; so if you set the min-width to 0 or initial will solve the problem

style.scss

.base-table { 
  p-dropdown {
    .ui-dropdown {
      min-width:0;
    }
  }
}

or like this will reset the min-width for p-dropdown component in the all project

 p-dropdown {
    .ui-dropdown {
      min-width:0; // auto , initial 😀
    }
  }

demo 🔥🔥

7
votes

You can add min-width:100% to p-dropdown element :

<p-dropdown [style]="{'width':'100%','min-width':'100%'}" *ngSwitchCase="'invoice_status'" [options]="statuses" [autoWidth]="true"></p-dropdown>
3
votes

Use this it might solve your problem

  <p-dropdown *ngSwitchCase="'status'" [options]="order_status" [style]="{ width: '100%', overflow: 'visible' }" appendTo="body"
          (onChange)="dt.filter($event.value, retailer.field, 'equals')"></p-dropdown>
3
votes

If someone comes in handy I will be glad:

p-table {
  ::ng-deep p-dropdown {
    .ui-dropdown {
      min-width: 0;
    }
  }
}
0
votes

You must put th in a tr tag:

See Prime Ng Filter Example from Site:

export class TableFilterDemo implements OnInit {

    cars: Car[];

    cols: any[];

    brands: SelectItem[];

    colors: SelectItem[];

    yearFilter: number;

    yearTimeout: any;

    constructor(private carService: CarService) { }

    ngOnInit() {
        this.carService.getCarsMedium().then(cars => this.cars = cars);

        this.brands = [
            { label: 'All Brands', value: null },
            { label: 'Audi', value: 'Audi' },
            { label: 'BMW', value: 'BMW' },
            { label: 'Fiat', value: 'Fiat' },
            { label: 'Honda', value: 'Honda' },
            { label: 'Jaguar', value: 'Jaguar' },
            { label: 'Mercedes', value: 'Mercedes' },
            { label: 'Renault', value: 'Renault' },
            { label: 'VW', value: 'VW' },
            { label: 'Volvo', value: 'Volvo' }
        ];

        this.colors = [
            { label: 'White', value: 'White' },
            { label: 'Green', value: 'Green' },
            { label: 'Silver', value: 'Silver' },
            { label: 'Black', value: 'Black' },
            { label: 'Red', value: 'Red' },
            { label: 'Maroon', value: 'Maroon' },
            { label: 'Brown', value: 'Brown' },
            { label: 'Orange', value: 'Orange' },
            { label: 'Blue', value: 'Blue' }
        ];

        this.cols = [
            { field: 'vin', header: 'Vin' },
            { field: 'year', header: 'Year' },
            { field: 'brand', header: 'Brand' },
            { field: 'color', header: 'Color' }
        ];
    }

    onYearChange(event, dt) {
        if (this.yearTimeout) {
            clearTimeout(this.yearTimeout);
        }

        this.yearTimeout = setTimeout(() => {
            dt.filter(event.value, 'year', 'gt');
        }, 250);
    }
}

and html File:

<p-table #dt [columns]="cols" [value]="cars" [paginator]="true" [rows]="10">
    <ng-template pTemplate="caption">
        <div style="text-align: right">        
            <i class="fa fa-search" style="margin:4px 4px 0 0"></i>
            <input type="text" pInputText size="50" placeholder="Global Filter" (input)="dt.filterGlobal($event.target.value, 'contains')" style="width:auto">
        </div>
    </ng-template>
    <ng-template pTemplate="header" let-columns>
        <tr>
            <th *ngFor="let col of columns">
                {{col.header}}
            </th>
        </tr>
        <tr>
            <th *ngFor="let col of columns" [ngSwitch]="col.field">
                <input *ngSwitchCase="'vin'" pInputText type="text" (input)="dt.filter($event.target.value, col.field, col.filterMatchMode)">
                <div *ngSwitchCase="'year'">
                    Value < {{yearFilter}}
                    <i class="fa fa-close" (click)="yearFilter=null;dt.filter(null, col.field, col.filterMatchMode)" style="cursor:pointer" *ngIf="yearFilter"></i>
                    <p-slider [style]="{'width':'100%','margin-top':'8px'}" [(ngModel)]="yearFilter" [min]="1970" [max]="2010" (onChange)="onYearChange($event, dt)"></p-slider>
                </div>
                <p-dropdown *ngSwitchCase="'brand'" [options]="brands" [style]="{'width':'100%'}" (onChange)="dt.filter($event.value, col.field, 'equals')"></p-dropdown>
                <p-multiSelect *ngSwitchCase="'color'" [options]="colors" defaultLabel="All Colors" (onChange)="dt.filter($event.value, col.field, 'in')"></p-multiSelect>
            </th>
        </tr>
    </ng-template>
    <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>
</p-table>
0
votes

You can add appendTo="body" property to p-dropdown. It will fix the issue if you have your dropdown inside the p-table body, without changing any CSS.

AppendTo target element to attach the overlay in primeNG p-dropdown

</p-table>
      ......
  <ng-template pTemplate="body" let-rowData>
    <tr>
       <td>
          <p-dropdown .... [options]="statuses" appendTo="body"></p-dropdown>
       </td>
    </tr>
  </ng-template>
</p-table>