2

新的反应和农业网格。我正在尝试在我的反应项目中实现一个简单的 ag-grid 示例。当我运行项目时,网格不显示。没有控制台警告,只是网格不显示。

import React from 'react';
import {AgGridReact} from 'ag-grid-react';
import '../../node_modules/ag-grid/dist/styles/ag-grid.css';
import '../../node_modules/ag-grid/dist/styles/theme-material.css';

var headers =  [{headerName: 'Name', field: 'name', width: 150, filter: 'text'},
                {headerName: 'Last', field: 'last', width: 150, filter: 'text'}]

var data = [{name: 'bob', last:'dude'},
            {name: 'will', last:'willdude'}]


export default class Accounts extends React.Component {
  constructor() {
    super();
    this.state = {
        showGrid: true,
        columnDefs: headers,
        rowData: data,
    };
  }
  onGridReady(params) {
      this.api = params.api;
      this.columnApi = params.columnApi;
  }

  render() {
    var gridTemplate;
    gridTemplate = (
        <div  className="ag-material">
            <AgGridReact
                columnDefs={this.state.columnDefs}
                rowData={this.state.rowData}
                onGridReady={this.onGridReady.bind(this)}
                showGrid={this.state.showGrid}
            />
        </div>
    );
    return (
      <div style={{width: '800px'}}>
        <p>I see this</p>
        {gridTemplate}
      </div>
    )
  }
}

这是我运行时看到的

4

3 回答 3

5

好的,我们需要父 div 的高度。

例如

    <div  className="ag-material" style={{height: '500px'}}>
        <AgGridReact
            columnDefs={this.state.columnDefs}
            rowData={this.state.rowData}
            onGridReady={this.onGridReady.bind(this)}
            showGrid={this.state.showGrid}
        />
    </div>
于 2016-12-05T01:57:45.273 回答
1

给出高度和宽度总是更好,否则 ag-grid 表将通过调整它以适合最小内容来呈现。

<div className="ag-material" style={{height: 500, width: 500}}>
        <AgGridReact
            columnDefs={this.state.columnDefs}
            rowData={this.state.rowData}
            onGridReady={this.onGridReady.bind(this)}
            showGrid={this.state.showGrid}
        />
</div>
于 2020-07-09T09:16:28.230 回答
0

当网格未渲染时,我看到了类似的问题。添加网格样式为我解决了这个问题。

import '../../node_modules/ag-grid/dist/styles/ag-grid.css';
import '../../node_modules/ag-grid/dist/styles/theme-material.css';
于 2020-06-23T14:52:37.353 回答