【问题标题】:ag-grid in jhipster angular 4jhipster angular 4中的ag-grid
【发布时间】:2018-05-27 11:46:41
【问题描述】:

我正在尝试在 jhipster 项目中使用 ag-grid。将 ag-grid 添加到我的项目后,我在 app.module 中导入了模块:

{AgGridModule} from 'ag-grid-angular';

我修改了组件以使用 ag-grid:

import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs/Rx';
import { JhiEventManager, JhiParseLinks, JhiAlertService } from 'ng-jhipster';

import { Typapp } from './typapp.model';
import { TypappService } from './typapp.service';
import { ITEMS_PER_PAGE, Principal, ResponseWrapper } from '../../shared';
import {ColDef, ColumnApi, GridApi} from 'ag-grid';

@Component({
    selector: 'jhi-typapp',
    templateUrl: './typapp.component.html'
})
export class TypappComponent implements OnInit, OnDestroy {
    typapps: Typapp[];
    typs: Typapp[]
    currentAccount: any;
    eventSubscriber: Subscription;
    /**
     * Declarations AG-GRID
     */
    // rowdata and column definitions
    rowData: Typapp[];
    columnDefs: ColDef[];
    // gridApi and columnApi
    api: GridApi;
    columnApi: ColumnApi;

    constructor(
        private typappService: TypappService,
        private jhiAlertService: JhiAlertService,
        private eventManager: JhiEventManager,
        private principal: Principal
    ) {
        this.columnDefs = this.createColumnDefs();
    }

    loadAll() {
        this.typappService.query().subscribe(
            (res: ResponseWrapper) => {
                this.typapps = res.json;
            },
            (res: ResponseWrapper) => this.onError(res.json)
        );
    }
    ngOnInit() {
        this.loadAll();
        this.principal.identity().then((account) => {
            this.currentAccount = account;
        });
        this.registerChangeInTypapps();
        /**
         * modif component aggrid
         */
        this.typappService.findAll().subscribe(
            (rowData) => {
                this.rowData = rowData
        },
            (error) => {
                console.log(error);
        }
        )
    }

    ngOnDestroy() {
        this.eventManager.destroy(this.eventSubscriber);
    }

    trackId(index: number, item: Typapp) {
        return item.id;
    }
    registerChangeInTypapps() {
        this.eventSubscriber = this.eventManager.subscribe('typappListModification', (response) => this.loadAll());
    }

    private onError(error) {
        this.jhiAlertService.error(error.message, null, null);
    }

    /**
     * AG GRID fonctions
     */
    // one grid initialisation, grap the APIs and auto resize the columns to fit the available space
    onGridReady(params): void {
        this.api = params.api;
        this.columnApi = params.columnApi;

        this.api.sizeColumnsToFit();
    }

    // create some simple column definitions
    private createColumnDefs() {
        return [
            {field: 'id'},
            {field: 'libTyp'},
        ]
    }
}

有component.html的代码

<h6> without AGRID</h6>
<div *ngFor="let rd of rowData">
    <span>{{rd.id}}</span>
    <span>{{rd.libTyp}}</span>
</div>
<br/>
<h6> with AGRID</h6>
<ag-grid-angular style="width: 100%; height: 800px;"
                 class="ag-theme-fresh"
                 (gridReady)="onGridReady($event)"
                 [columnDefs]="columnDefs"
                 [rowData]="rowData">
</ag-grid-angular>

结果如下:

我做错了什么?为什么我使用 ag-grid 时没有结果?

即使在控制台中也没有错误。

非常感谢。

【问题讨论】:

    标签: jhipster ag-grid


    【解决方案1】:

    我有同样的问题。您是否将ag-theme-fresh.css 导入到vendor.css?这对我有用。

    \src\main\webapp\content\css\vendor.css:

    ...
    @import '~ag-grid/dist/styles/ag-theme-fresh.css';
    

    【讨论】:

    • 我也有同样的问题,我使用的是 sass,所以 Jhipster 默认不提供 vendor.css,我尝试了同样的方法,但对我没有任何想法?
    猜你喜欢
    • 2019-06-08
    • 2018-08-11
    • 2018-02-15
    • 2018-10-26
    • 1970-01-01
    • 2021-09-03
    • 2022-10-19
    • 2018-05-01
    • 1970-01-01
    相关资源
    最近更新 更多