visit
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { WjGridModule } from '@grapecity/wijmo.angular2.grid';
import { WjGridFilterModule } from '@grapecity/wijmo.angular2.grid.filter';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
WjGridModule,
WjGridFilterModule
],
declarations: [
AppComponent
],
bootstrap: [
AppComponent
]
})
export class AppModule { }
app.component.ts
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import * as WjCore from '@grapecity/wijmo';
styles.css
@import "wijmo/styles/themes/wijmo.theme.material.css";
body {
font-family: Lato, Arial, Helvetica;
}
.wj-flexgrid { /* limit the grid's width and height */
max-height: 300px;
max-width: 32em;
}
Our data source will be stored within our app.component.ts file, whichis defined as follows:
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import * as WjCore from '@grapecity/wijmo';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
// create our CollectionView
data = new WjCore.CollectionView([], {
groupDescriptions: ['make'] // group my make
});
// and populate it from the JSON data source
// the data is stored in a //jsonbin.io/ public repo
constructor(private http: HttpClient) {
this.http.get('//api.jsonbin.io/b/5f0765bc5d4af74b01295f26')
.subscribe(data => {
this.data.sourceCollection = data;
});
}
}
The app.component.ts file exposes the data through its "data" property, a CollectionView grouped by make. The data is loaded asynchronously after the component is constructed.
When the data is received, it is assigned to the CollectionView's sourceCollection property and becomes available to the application.
The final step is implementing the markup inside of the app.component.html file to render the Angular DataGrid:
<h1>
2021 Sedans (Angular)
</h1>
<p>
Sort by model and price by clicking the column headers.
Filter by value or condition by clicking the filter icons
in the column headers.
Collapse and expand makes to see all the models.
Select one or more models with the mouse or keyboard and
copy your selection to the clipboard.</p>
<p>
Showing
<b>{{data.items.length}}</b> models from
<b>{{data.groups.length}}</b> makes.
</p>
<wj-flex-grid [allowResizing]="'None'" [showAlternatingRows]="false" [isReadOnly]="true" [selectionMode]="'ListBox'"
[headersVisibility]="'Column'" [itemsSource]="data">
<wj-flex-grid-column [binding]="'make'" [header]="'Make'" [width]="'*'" [visible]="false"></wj-flex-grid-column>
<wj-flex-grid-column [binding]="'model'" [header]="'Model'" [width]="'*'"></wj-flex-grid-column>
<wj-flex-grid-column [binding]="'price'" [header]="'Price'" [format]="'c0'" [aggregate]="'Avg'" [width]="'.5*'"></wj-flex-grid-column>
<wj-flex-grid-filter></wj-flex-grid-filter>
</wj-flex-grid>
The app header contains a short app description and a summary of how many models and makes are displayed. The summary counts are updated automatically when the user filters the data. The header is followed by the "FlexGrid" element, which initializes the grid's properties, including the itemsSource, the columns to display, and their properties.
The column properties include the binding, header, format, and width for each column. Note that the aggregate property on the price column causes the grid to show the average price for each make in the group headers.