我在让 ag-Grid 与我的 react 应用程序一起工作时遇到问题。无论我尝试什么,我只得到一些文本,我看不到网格。我不知道我错过了什么。这是我的代码:
/*
* ----------------------------
* index.js
* ----------------------------
*/
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import { BrowserRouter } from 'react-router-dom'
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>
, document.getElementById('root'));
registerServiceWorker();
/*
* ----------------------------
* App.js
* ----------------------------
*/
import React, { Component } from 'react';
import Header from './Header';
import Main from './Main';
import './Styles/App.css';
class App extends Component {
render() {
return (
<div className="App">
<Header />
<Main />
</div>
);
}
}
export default App;
/*
* ----------------------------
* Header.js
* ----------------------------
*/
import React, { Component } from 'react';
import { Link } from 'react-router-dom'
import './Styles/Header.css';
class Header extends Component {
render() {
return (
<div className="App-header">
<h2>MY APPLICATION</h2>
<Link to='/'>Home</Link>
<Link to='/cities'>Cities</Link>
<Link to='/countries'>Countries</Link>
</div>
);
}
}
export default Header;
/*
* ----------------------------
* Main.js
* ----------------------------
*/
import React, { Component } from 'react';
import { Switch, Route } from 'react-router-dom';
import Home from './Pages/Home';
import Stations from './Pages/Cities';
import Countries from './Pages/Countries';
class Main extends Component {
render() {
return (
<div className="App-main">
<Switch>
<Route exact path='/' component={Home}/>
<Route path='/cities' component={Cities}/>
<Route path='/countries' component={Countries}/>
</Switch>
</div>
);
}
}
export default Main;
/*
* ----------------------------
* Countries.js
* ----------------------------
*/
import React, { Component } from 'react';
import { AgGridReact } from 'ag-grid-react';
class Countries extends Component {
constructor(props) {
super(props);
this.state = {
columnDefs: this.createColumnDefs(),
rowData: this.createRowData()
};
}
createColumnDefs() {
return [
{headerName: "#", width: "30px", checkboxSelection: true, suppressSorting: true, suppressMenu: true, pinned: true },
{headerName: "Name", field: "name"},
{headerName: "Abbreviation", field: "abbr"},
{headerName: "id", field: "id"}
];
}
createRowData() {
return [
{name: "Sweden", id: 1, abbr: "SE"},
{make: "Denmark", id: 2, abbr: "DK"},
{make: "Norway", id: 3, abbr: "NO"}
];
}
render() {
let containerStyle = {
height: '800px',
width: '500px',
margin: 'auto'
};
//console.log(this.state.columnDefs);
return (
<div>
<div style={containerStyle} className="ag-fresh">
<AgGridReact
// properties
columnDefs={this.state.columnDefs}
rowData={this.state.rowData}
groupHeaders="false"
rowSelection="multiple"
enableColResize="true"
enableSorting="true"
enableFilter="true"
rowHeight="22"
debug="true"
/>
</div>
</div>
)
}
};
export default Countries;
我没有包含一些 CSS 文件,Home.js
并且Cities.js
因为它们目前没有呈现任何内容。这是我得到的结果:
如您所见,我没有看到网格,只是一些奇怪的文字。我一直在浏览 ag-grid 主页并尝试他们的示例代码,但我一直都得到这个。
有任何想法吗?