2

I have a problem with the DataTable of primeng with Angular 2 when I use sub object. When I put the editable parameter at true. The value disappear.

This is my object :

export class Car {
      year: number;
      type: {`enter code here`
        brand: string;
        model: string;
      };
      color: string;
  }

This is my component :

import { Component, OnInit } from '@angular/core';

import { CARS } from './mock-cars';
import { Car } from './cars';


@Component({
  moduleId: module.id,
  selector: 'app-cars',
  templateUrl: 'cars.component.html'
})
export class CarComponent implements OnInit {
  cars: Car[] = [];
  cols: any[];

  constructor() { }

  ngOnInit(): void {
    this.cars = CARS;

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

And this is my html :

    <h3>Cars</h3>
<div class="grid grid-pad">
  <p-dataTable [value]="cars">
    <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header" [editable]=true></p-column>
  </p-dataTable>

  <p-dataTable [value]="cars">
    <p-column [editable]=true field="year" header="Vin"></p-column>
    <p-column [editable]=true field="type.brand" header="Year"></p-column>
    <p-column [editable]=true field="type.model" header="Brand"></p-column>
    <p-column [editable]=true contenteditable=""field="color" header="Color"></p-column>
</p-dataTable>
</div>

If editable is false, I can see the value

Non editable table:

enter image description here

But if editable is true, the value of the sub object disappear :

Editable table:

enter image description here

Someone else have this problem? I don't know if it's a bug in primeng or if I miss something.

Thanks ! :)

2
  • Can you try to update to 2.0.RC1 which is released 45 mins ago which provides customizable editable cells feature and bug-fixes. Commented Jan 20, 2017 at 8:23
  • Hi, thanks for the reply. I change the version and it doesn"t work. I have the same problem. Commented Jan 20, 2017 at 18:38

1 Answer 1

0

Have you tried adding templates ?

<p-column [editable]=true field="type" header="Year">
  <template let-col let-car="rowData" pTemplate="editor">
    <input type="text" pInputText [(ngModel)]="car[col.field]?.brand" [class]="'form-control'" required="true" placeholder="">
  </template>
</p-column>

Also please add editable attribute on <p-datatable>.

More on Templating #here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.