我按照该教程轻松设置了AngularJS的agGrid,但事实是我也使用typescript而不是javascript。 我确实做到了:
npm install ag-grid
var AgGrid = require('ag-grid');
AgGrid.initialiseAgGridWithAngular1(angular);
var module = angular.module("example", ["agGrid"]);
然后在我的html中使用它并显示出来:
<div ag-grid="$ctrl.gridOptions" class="ag-theme-balham" style="height: 100%;"></div>
所以我尝试添加一些要求:
require("ag-grid/dist/styles/ag-grid.css")
require("ag-grid/dist/styles/ag-theme-balham.css")
var AgGrid = require('ag-grid');
但是仍然没有任何想法吗?谢谢
答案 0 :(得分:0)
我正在使用基本主题,它对我有用。下面是相同的代码。
//**Layout Page**
<link rel="stylesheet" href="~/Content/ag-grid.css">
//If you're using the bundled version, you can reference the ag-Grid-Enterprise library via CDN
<script src="_url_to_your_chosen_cdn_/ag-grid-enterprise.js"></script>
//Load from Local
//<script src="node_modules/ag-grid/dist/ag-grid-enterprise.js"></script>
<script type="text/javascript">
// Update angular grid license key. If you are using Enterprise Version
agGrid.LicenseManager.setLicenseKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
// get ag-Grid to create an Angular module and register the ag-Grid directive
agGrid.initialiseAgGridWithAngular1(angular);
var app = angular.module("AppName", ["agGrid"]);
</script>
//**View**
<div ag-grid="agGridOptions" class="ag-theme-fresh" style="height: 400px;"></div>
//**ControllerJS**
$scope.agGridOptions = {
angularCompileRows: true,
columnDefs: columnDefs,
rowData: rowData,
}
答案 1 :(得分:0)
我终于找到了官方文档中思想丰富的部分。
因此,有一些易于使用的步骤:
npm install ag-grid-community
var AgGrid = require('ag-grid-community');
AgGrid.initialiseAgGridWithAngular1(angular);
在您的课堂上还是我的情况下,我的组件
import { Grid, GridOptions} from "ag-grid-community";
import "ag-grid-community/dist/styles/ag-grid.css";
import "ag-grid-community/dist/styles/ag-theme-balham.css";
然后使用您的网格!
this.gridOptions = {
columnDefs: this.createColumnDefs(),
rowData: this.createRowData()
};
let eGridDiv:HTMLElement = <HTMLElement>document.querySelector('#myGrid');
new Grid(eGridDiv, this.gridOptions);
private createColumnDefs() {
return [
{headerName: "Make", field: "make"},
{headerName: "Model", field: "model"},
{headerName: "Price", field: "price"}
];
}
private createRowData() {
return [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];
}