私はAngular 4プロジェクトでag-gridを使用しています。サーバからデータをグリッドで表示
サーバーからデータを取得してテーブルに表示しようとしましたが、データは存在しますが、テーブルは空のままです。
問題がどこにあるかを確認するために、同じデータを生成する*ngFor
があり、画面に表示されていることがわかります。
手動で(ハードコードされて)書き込むと、グリッドにデータを表示することもできます。ページがロードされると、ajaxリクエストなしで解析されます。
HTML:
<div style="width: 200px;">
<ag-grid-angular #agGrid style="width: 100%; height: 200px;" class="ag-fresh"
[gridOptions]="gridOptions">
</ag-grid-angular>
</div>
<table class="table">
<tr>
<th>
Foo
</th>
<th>
Bar
</th>
</tr>
<tr *ngFor="let item of gridOptions.rowData; let myIndex = index">
<td>
{{item.foo}}
</td>
<td>
{{item.bar}}
</td>
</tr>
</table>
TS:
export class HomeComponent implements OnInit {
private gridOptions: GridOptions;
constructor(
private adsService: AdsService
) {
this.gridOptions = {};
this.gridOptions.columnDefs = [
{
headerName: "Foo",
field: "foo",
width: 100
},
{
headerName: "Bar",
field: "bar",
width: 100
},
];
this.gridOptions.rowData = [];
}
ngOnInit(){
this.myService
.getAll()
.subscribe(item => this.gridOptions.rowData = item);
}
}
は、だから私はおそらく、私はちょうどそれを行う方法がわからない、何とかAG-グリッドはデータが変更されたことを知らせる必要があります。 plunkerの作業
グレート!ありがとう、それは私が24時間で賞金を授与することができると言います。私が忘れた場合に備えて私に思い出させてください。 – Alon
心配はいりません。聞いてうれしいそれはあなたに役立ちます:) – trungk18