页面上看不到KendoUI网格

时间:2016-10-16 21:47:12

标签: angular kendo-grid

我正在开发使用KendoUI datagrid的Angular 2应用程序。出于某种原因,我只能看到网格,而不是数据。有人能告诉我我可能缺少什么。

UI如下所示

enter image description here

以下是我的源代码

风险list.Component.ts

import { Component, OnInit } from '@angular/core';
import { Risk } from './risk';
import { RiskService } from './risk.service';

@Component({
    moduleId: module.id,
    selector: 'rm-risks',
    templateUrl: '/app/risk-list.component.html',
    providers: [RiskService]
})

export class RiskListComponent implements OnInit {
    title = 'Risk List';
     risks: Risk[];

    constructor(private _riskService: RiskService) {
        console.log(this.risks);
    }

    getRisks(): void {
        this._riskService.getRisks().then(risks => this.risks = risks);

    }

    ngOnInit(): void {
        this.getRisks();
    }
};

风险list.component.html

<kendo-grid [data]="risks">
    <kendo-grid-column field="reference">
        <template kendoHeaderTemplate let-column let-columnIndex="columnIndex">
            {{column.field}}({{columnIndex}})
        </template>
    </kendo-grid-column>
    <kendo-grid-column field="insuredName">
        <template kendoHeaderTemplate let-column let-columnIndex="columnIndex">
            {{column.field}}({{columnIndex}})
        </template>
    </kendo-grid-column>
    <kendo-grid-column field="inceptionDate">
        <template kendoHeaderTemplate let-column let-columnIndex="columnIndex">
            {{column.field}}({{columnIndex}})
        </template>
    </kendo-grid-column>
    <kendo-grid-column field="riskType">
        <template kendoHeaderTemplate let-column let-columnIndex="columnIndex">
            {{column.field}}({{columnIndex}})
        </template>
    </kendo-grid-column>
    <kendo-grid-column field="status">
        <template kendoHeaderTemplate let-column let-columnIndex="columnIndex">
            {{column.field}}({{columnIndex}})
        </template>
    </kendo-grid-column>
    <kendo-grid-column field="grossPremium">
        <template kendoHeaderTemplate let-column let-columnIndex="columnIndex">
            {{column.field}}({{columnIndex}})
        </template>
    </kendo-grid-column>
    <kendo-grid-column field="allocatedTo">
        <template kendoHeaderTemplate let-column let-columnIndex="columnIndex">
            {{column.field}}({{columnIndex}})
        </template>
    </kendo-grid-column>
    <kendo-grid-column field="allocatedCompany">
        <template kendoHeaderTemplate let-column let-columnIndex="columnIndex">
            {{column.field}}({{columnIndex}})
        </template>
    </kendo-grid-column>
</kendo-grid>

risk.service.ts

import { Injectable } from '@angular/core';
import { Risk } from './risk';
import { Risks } from './mock-risk';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';


@Injectable()
export class RiskService {

    getRisks(): Promise<Risk[]> {
        return Promise.resolve(Risks);
    }

}

risk.ts

export class Risk {
    riskId: number;
    reference: string;
    insuredName: string;
    inceptionDate: string;
    riskType: string;
    status: string;
    grossPremium: number;
    allocatedTo: string;
    allocatedCompany: string;

}

模拟risk.ts

import { Risk } from './risk'

export const Risks: Risk[] = [

    {

        "riskId": 1,
        "reference": "HISC9308336",
        "insuredName": "SA 84161",
        "inceptionDate": "March 19, 2016",
        "riskType": "Quote",
        "status": "Indication",
        "grossPremium": 100,
        "allocatedTo": "Broker User",
        "allocatedCompany": "Broker"
    },
    {

        riskId: 2,
        reference: "HISC9308337",
        insuredName: "SA 84161",
        inceptionDate: 'April 22, 2016',
        riskType: 'Quote',
        status: 'Indication',
        grossPremium: 300,
        allocatedTo: 'Broker User',
        allocatedCompany: 'Broker'
    }

];

risks.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { RiskListComponent } from './risk-list.component';
import { RiskService } from './risk.service';
import { RiskRoutingModule } from './risks-routing.module';
import { GridModule } from '@progress/kendo-angular-grid';
@NgModule({
    imports: [
        CommonModule,
        FormsModule,
        RiskRoutingModule,
        GridModule

    ],
    declarations: [
        RiskListComponent
    ],
    providers: [
        RiskService
    ]
})
export class RisksModule { }

风险-routing.module.ts

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { RiskListComponent } from './risk-list.component';

@NgModule({
    imports: [
        RouterModule.forChild([
            { path: 'risks', component: RiskListComponent }
        ])
    ],
    exports: [
        RouterModule
    ]
})
export class RiskRoutingModule { }

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。我使用以下代码更新了我的视图并且它有效。

<强>风险list.component.html

<kendo-grid [data]="risks">
    <kendo-grid-column field="reference" title="Reference" width="120">
    </kendo-grid-column>
    <kendo-grid-column field="insuredName" title="Insured Name">
    </kendo-grid-column>
    <kendo-grid-column field="inceptionDate" title="Inception Date" width="230">
    </kendo-grid-column>
    <kendo-grid-column field="riskType" title="Risk Type" width="120">
    </kendo-grid-column>
    <kendo-grid-column field="Status" title="Status">
    </kendo-grid-column>
    <kendo-grid-column field="grossPremium" title="Gross Premium" width="230">
    </kendo-grid-column>
    <kendo-grid-column field="allocatedTo" title="Allocated To" width="120">
    </kendo-grid-column>
    <kendo-grid-column field="allocatedCompany" title="Allocated Company">
    </kendo-grid-column>
    <kendo-grid-column field="Discontinued" width="120">
        <template kendoCellTemplate let-dataItem>
            <input type="checkbox" [checked]="dataItem.Discontinued" disabled />
        </template>
    </kendo-grid-column>
</kendo-grid>