简体   繁体   English

Ag-grid React 标题未显示

[英]Ag-grid React header not displaying

I am creating a simple Ag-Grid in React.我正在 React 中创建一个简单的 Ag-Grid。 However, I cannot figure out why the header is blank on the local host although I have specified header names for each column.但是,尽管我为每列指定了标题名称,但我无法弄清楚为什么本地主机上的标题为空白。 I have tried adjusting the height and wrapping the text of each header.我尝试调整高度并包装每个标题的文本。 I am using ag-theme-alpine.我正在使用 ag-theme-alpine。

import React, { useState } from "react";
import { AgGridReact } from "ag-grid-react";
import 'ag-grid-enterprise';
import 'ag-grid-community/dist/styles/ag-grid.css';
import 'ag-grid-community/dist/styles/ag-theme-alpine.css';

const InitialRowData = [
    { year: 1 },
    { year: 2 },
    { year: 3 }
];

const columnDefs = [
    { headerName: 'year', field: 'year', width: 20 },
    { headerName: 'premium', field: 'premium', width: 90, editable: true, enableRangeSelection: true }
];

export function MyGrid() {

    const [rowData, setRowData] = useState(InitialRowData);
    return (
        <div className="ag-theme-alpine" style={{ height: 900, width: 200 }}>
            <AgGridReact

                rowData={rowData}
                columnDefs={columnDefs}
                enableRangeSelection={true}
            >
            </AgGridReact>
        </div>

    );
}

The year heading is not visible because the column width of 20 is too small for it to display.年份标题不可见,因为 20 的列宽太小而无法显示。 If you make the column resizeable then you will be able to drag the width up and down and see how the headerName displays.如果您使列可调整大小,那么您将能够上下拖动宽度并查看 headerName 的显示方式。

{ headerName: 'year', field: 'year', resizable: true, width: 20,  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM