primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Is it possible to add a drop-down to an editable data table?

Open mikosu3 opened this issue 10 years ago • 6 comments

I tried the code below, but I did not expect it. Is there any way?

<p-dataTable [value]="cars" sortMode="multiple" [editable]="true" [rows]="10" [paginator]="true" [globalFilter]="gb">
    <header>Car List</header>
    <p-column field="vin" header="Vin" [sortable]="true" [filter]="true"></p-column>
    <p-column field="year" header="Year" [sortable]="true" [editable]="true" [filter]="true" filterMatchMode="contains"></p-column>
    <p-column field="brand" header="Bland" [sortable]="true" [editable]="true" [filter]="true" filterMatchMode="contains"></p-column>
    <p-column field="type" header="Body Type" [editable]="true" [filter]="true">
        <template let-car="rowData" pTemplate type="body">
            <p-dropdown [options]="types" [(ngModel)]="car.type"></p-dropdown>
        </template>
    </p-column>
</p-dataTable>
export class CarsComponent implements OnInit {
  cars: Car[];
  types: any[];

  constructor(private carService: CarService) { }

  ngOnInit() {
    this.carService.getCarsSmall().then(cars => this.cars = cars);
    this.types = [
      {value: 1, label: "Sedan"},
      {value: 2, label: "Coupe"},
      {value: 3, label: "Wagon"},
      {value: 4, label: "Mini"},
      {value: 5, label: "SUV"},
    ];
  }
}

mikosu3 avatar Nov 21 '16 07:11 mikosu3

@mikosu3 did you find the solution for your problem? I am facing a similar issue. When a new car object is added, the value in all dropdowns is same. Let me know if you need any more details from my side.

supriya2992 avatar Nov 29 '16 06:11 supriya2992

@supriya2992 I responded with the following sources. editable to false

<p-column field="type" header="Body Type" [editable]="false" [filter]="true">
    <template let-car="rowData" pTemplate type="body">
        <select [(ngModel)]="car.type" [ngStyle]='{"width": "100%","border": "none", "background": "rgba(255,255,255,0)"}'>
            <option *ngFor="let row of types" [value]="row.value">{{row.label}}</option>
        </select>
    </template>
</p-column>

mikosu3 avatar Nov 30 '16 00:11 mikosu3

Oh ok thanks. So basically you have used normal HTML select instead of primeng dropdown.

supriya2992 avatar Dec 01 '16 06:12 supriya2992

@mikosu3 I am still facing the problem if i use html select instead of p-dropdown.

supriya2992 avatar Dec 05 '16 12:12 supriya2992

@supriya2992 Have you set the editable option to false?

I solved it this way in the meantime. But I think that the way I do is not the best

mikosu3 avatar Dec 06 '16 04:12 mikosu3

Issue with editable datatable with dropdown. On editing the data from dropdown then the value of the shwoing in the table, which should be lable.

Example: Dropdown Example value label 1 Newyork 2 Auli

On the selection of city id 1 Newyork (label) should be displayed there, not its value. Currently its displaying 1 instead of Newyork

kaushalkishorejaiswal avatar May 24 '17 09:05 kaushalkishorejaiswal