2

我有一个带有一些简单虚拟数据的基本 ag-grid,但它仅在我不导入库提供的 .css 文件时才显示,即使这样它也显示不正确。

摘自我的 package.json:

"ag-grid": "10.0.1",
"ag-grid-react": "10.0.0",
"react": "15.4.2"

从我的 React 组件:构造函数:

this.state = { columnDefs: [{headerName: 'Product', field: 'product'},{headerName: 'Country', field: 'country'}], rowData: [{product: 'IOL', country: 'US'}, {product: 'Suture', country: 'IN'}]}

从渲染():

return (
        <div id='grid'>
            {/*<div id='grid' className='ag-fresh'>*/}
            <div>
                Here's the grid...
            </div>
            <AgGridReact

                // listen for events with React callbacks
                onGridReady={this.onGridReady.bind(this)}
                // onRowSelected={this.onRowSelected.bind(this)}
                // onCellClicked={this.onCellClicked.bind(this)}

                // binding to properties within React State or Props
                showToolPanel={this.state.showToolPanel}
                quickFilterText={this.state.quickFilterText}
                icons={this.state.icons}

                // column definitions and row data are immutable, the grid
                // will update when these lists change
                columnDefs={this.state.columnDefs}
                rowData={this.state.rowData}

                // or provide props the old way with no binding
                rowSelection="multiple"
                enableSorting="true"
                enableFilter="true"
                rowHeight="22"
            />
        </div>)

如果我在不导入任何 .css 的情况下运行此代码,我会得到一个混乱的网格,例如: 在此处输入图像描述

现在,如果我按照入门指南导入 css:

import 'ag-grid-root/dist/styles/ag-grid.css'  // see webpack config for alias of 'ag-grid-root'
import 'ag-grid-root/dist/styles/theme-fresh.css'

...然后网格的任何部分都不会显示(只有我在网格之前的 div)。导入 css 后,我是否为网格分配了主题都没有关系,没有任何显示。

4

1 回答 1

2

我有一个类似的问题,数据行没有显示,只是分页。设置固定的 div 高度可以使行显示,但添加domLayout: 'autoHeight'到 gridOptions 意味着它始终是正确显示的正确高度。

于 2019-03-26T17:15:38.350 回答