我使用ag-网格角显示表格格式的数据,但所有的数据被杂乱成一列。
我正在使用原始数据来填充ag网格。
我的component.ts文件
import { Component, OnInit } from '@angular/core';
import {AgGridModule} from 'ag-grid-angular/main';
import {GridOptions} from 'ag-grid';
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.css']
})
export class MainComponent implements OnInit {
gridOptions: GridOptions;
columnDefs= [
{headerName: 'Pokemon', field: 'name'},
{headerName: 'Type', field: 'type'},
{headerName: 'Price', field: 'price'},
];
rowData = [
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000},
{name : 'Bulbasaur', type: 'plant', price: 1000}
];
constructor() {
this.gridOptions = <GridOptions>{
rowCount: 10
};
}
ngOnInit() {
}
}
rowData和colDefs在上面的代码中声明。
我的component.html代码:
<h1>Grid example</h1>
<ag-grid-angular class = "ag-fresh"
[rowData]="rowData"
[columnDefs]="columnDefs"
[gridOptions]="gridOptions"
>
</ag-grid-angular>
我的app.module.ts文件:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { MainComponent } from './main/main.component';
import {AgGridModule} from 'ag-grid-angular';
@NgModule({
declarations: [
AppComponent,
MainComponent
],
imports: [
BrowserModule,
AgGridModule.withComponents(MainComponent)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
发布于 2018-03-15 17:25:10
将以下内容添加到.angular-cli.json的styles部分
"../node_modules/ag-grid/dist/styles/ag-grid.css",
"../node_modules/ag-grid/dist/styles/theme-fresh.css",
发布于 2018-03-22 14:18:14
在关于构建底部有角CLI (https://www.ag-grid.com/ag-grid-angular-angularcli/#creating-a-angular-project-with-ag-grid)的ag-Grid的教程中,它们告诉您将ag-Grid的样式表放到角-cli.json文件中。就像伊莎比描述的那样。
要完成答案,而不仅仅是发布链接:将以下两行添加到.angular-cli.json文件中:
"../node_modules/ag-grid/dist/styles/ag-grid.css",
"../node_modules/ag-grid/dist/styles/ag-theme-balham.css"
根据您使用的主题更改第二行。
https://stackoverflow.com/questions/47928150
复制相似问题