2017-01-19 7 views
2

サブオブジェクトを使用すると、primengの​​DataTableにAngular 2という問題があります。 編集可能なパラメータをtrueに設定します。値は消えます。PrimeNgのDataTableの編集可能なパラメータがAngular2で動作しない

これは私の物である:

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

これは私のコンポーネントである:

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'} 
     ]; 
    } 
} 

そして、これは私のhtmlです:編集可能がfalseの場合

<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> 

、私が見ることができます値

編集不可能なタBLE:

enter image description here

でも編集可能がtrueの場合は、サブオブジェクトの値が消える:

編集可能なテーブル:他

enter image description here

誰かがこの問題を持っていますか? primengの​​バグなのか、何かが恋しいのか分かりません。

ありがとうございます! :)

+0

をテンプレート上

よりますが備わり、バグフィックスカスタマイズ編集可能なセルを提供する45分前にリリースされた2.0.RC1に更新しようとすることができます。 –

+0

こんにちは、返信いただきありがとうございます。私はバージョンを変更しても動作しません。同じ問題があります。 –

答えて

0

テンプレートを追加しようとしましたか?

<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> 

<p-datatable>にも編集可能な属性を追加してください。 #here

関連する問題