Reputation: 501
I followed the tutorial to easily set up agGrid fot AngularJS, the thing is I also use typescript instead javascript. I actually did :
npm install ag-grid
var AgGrid = require('ag-grid');
AgGrid.initialiseAgGridWithAngular1(angular);
var module = angular.module("example", ["agGrid"]);
Then use it with in my html and it's showing up:
<div ag-grid="$ctrl.gridOptions" class="ag-theme-balham" style="height: 100%;"></div>
So I tried to add some require:
require("ag-grid/dist/styles/ag-grid.css")
require("ag-grid/dist/styles/ag-theme-balham.css")
var AgGrid = require('ag-grid');
But still not working any ideas? Thanks
Upvotes: 1
Views: 3709
Reputation: 501
I finally find out looking thought parts of the official doc.
So there is the steps to use it easily:
npm install ag-grid-community
var AgGrid = require('ag-grid-community');
AgGrid.initialiseAgGridWithAngular1(angular);
In your class or in my case my component
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";
Then Use your Grid!
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}
];
}
Upvotes: 1
Reputation: 369
I am using basic theme and it works for me. Below is the code for the same.
//**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,
}
Upvotes: 1