Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 2d816da

Browse files
committed
feat: add example for custom header and footer
1 parent 49947f5 commit 2d816da

File tree

5 files changed

+117
-1
lines changed

5 files changed

+117
-1
lines changed

src/app/app-routing.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { GridTradingComponent } from './examples/grid-trading.component';
3232
import { GridTreeDataHierarchicalComponent } from './examples/grid-tree-data-hierarchical.component';
3333
import { GridTreeDataParentChildComponent } from './examples/grid-tree-data-parent-child.component';
3434
import { SwtCommonGridTestComponent } from './examples/swt-common-grid-test.component';
35+
import { GridHeaderFooterComponent } from './examples/grid-header-footer.component';
3536

3637
import { NgModule } from '@angular/core';
3738
import { Routes, RouterModule } from '@angular/router';
@@ -72,6 +73,7 @@ const routes: Routes = [
7273
{ path: 'tree-data-parent-child', component: GridTreeDataParentChildComponent },
7374
{ path: 'tree-data-hierarchical', component: GridTreeDataHierarchicalComponent },
7475
{ path: 'swt', component: SwtCommonGridTestComponent },
76+
{ path: 'header-footer', component: GridHeaderFooterComponent },
7577
{ path: '', redirectTo: '/trading', pathMatch: 'full' },
7678
{ path: '**', redirectTo: '/trading', pathMatch: 'full' }
7779
];

src/app/app.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@
148148
33- Real-Time Trading Platform
149149
</a>
150150
</li>
151+
<li class="nav-item">
152+
<a class="nav-link" routerLinkActive="active" [routerLink]="['/header-footer']">
153+
34- Custom header &amp; footer templates
154+
</a>
155+
</li>
151156
</ul>
152157
</section>
153158

src/app/app.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { AngularSlickgridModule } from './modules/angular-slickgrid/modules/angu
6161
// load necessary Flatpickr Locale(s), but make sure it's imported AFTER the SlickgridModule import
6262
import 'flatpickr/dist/l10n/fr';
6363
import { CustomButtonFormatterComponent } from './examples/custom-buttonFormatter.component';
64+
import { CustomFooterComponent, GridHeaderFooterComponent } from './examples/grid-header-footer.component';
6465

6566
// AoT requires an exported function for factories
6667
export function createTranslateLoader(http: HttpClient) {
@@ -130,7 +131,9 @@ export function appInitializerFactory(translate: TranslateService, injector: Inj
130131
SwtCommonGridTestComponent,
131132
SwtCommonGridPaginationComponent,
132133
SwtCommonGridComponent,
133-
HomeComponent
134+
HomeComponent,
135+
GridHeaderFooterComponent,
136+
CustomFooterComponent
134137
],
135138
imports: [
136139
AppRoutingRoutingModule,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<div id="demo-container" class="container-fluid">
2+
<h2>
3+
{{ title }}
4+
<span class="float-end">
5+
<a
6+
style="font-size: 18px"
7+
target="_blank"
8+
href="https://github.com/ghiscoding/Angular-Slickgrid/blob/master/src/app/examples/grid-header-footer.component.ts"
9+
>
10+
<span class="fa fa-link"></span> code
11+
</a>
12+
</span>
13+
</h2>
14+
<div class="subtitle" [innerHTML]="subTitle"></div>
15+
16+
<angular-slickgrid
17+
gridId="grid1"
18+
[columnDefinitions]="columnDefinitions"
19+
[gridOptions]="gridOptions"
20+
[dataset]="dataset"
21+
>
22+
<ng-template #slickgridHeader>
23+
<h3>Grid with header and footer slot</h3>
24+
</ng-template>
25+
26+
<ng-template #slickgridFooter>
27+
<custom-footer></custom-footer>
28+
</ng-template>
29+
</angular-slickgrid>
30+
</div>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { Column, GridOption, Formatters } from './../modules/angular-slickgrid';
3+
4+
const NB_ITEMS = 995;
5+
6+
@Component({
7+
template: `<button (click)="clickMe()">I'm a button from an Angular component (click me)</button>
8+
<div *ngIf="clickedTimes">You've clicked me {{clickedTimes}} time(s)</div>`,
9+
selector: 'custom-footer',
10+
})
11+
export class CustomFooterComponent {
12+
clickedTimes = 0;
13+
14+
clickMe() {
15+
this.clickedTimes++;
16+
}
17+
}
18+
19+
@Component({
20+
templateUrl: './grid-header-footer.component.html',
21+
})
22+
export class GridHeaderFooterComponent implements OnInit {
23+
title = 'Example 34: Custom header & footer Templates';
24+
subTitle = `
25+
Basic Grid with templates for custom headers and footers
26+
<ul>
27+
<li>Pass in custom templates to be rendered at predefined header and footer destinations</li>
28+
</ul>
29+
`;
30+
31+
columnDefinitions: Column[] = [];
32+
gridOptions!: GridOption;
33+
dataset!: any[];
34+
35+
ngOnInit(): void {
36+
this.columnDefinitions = [
37+
{ id: 'title', name: 'Title', field: 'title', sortable: true },
38+
{ id: 'duration', name: 'Duration (days)', field: 'duration', sortable: true },
39+
{ id: '%', name: '% Complete', field: 'percentComplete', sortable: true },
40+
{ id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso },
41+
{ id: 'finish', name: 'Finish', field: 'finish', formatter: Formatters.dateIso },
42+
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', sortable: true }
43+
];
44+
this.gridOptions = {
45+
enableAutoResize: false,
46+
enableSorting: true,
47+
gridHeight: 225,
48+
gridWidth: 800,
49+
};
50+
51+
this.dataset = this.mockData(NB_ITEMS);
52+
}
53+
54+
mockData(count: number) {
55+
// mock a dataset
56+
const mockDataset = [];
57+
for (let i = 0; i < count; i++) {
58+
const randomYear = 2000 + Math.floor(Math.random() * 10);
59+
const randomMonth = Math.floor(Math.random() * 11);
60+
const randomDay = Math.floor((Math.random() * 29));
61+
const randomPercent = Math.round(Math.random() * 100);
62+
63+
mockDataset[i] = {
64+
id: i,
65+
title: 'Task ' + i,
66+
duration: Math.round(Math.random() * 100) + '',
67+
percentComplete: randomPercent,
68+
start: new Date(randomYear, randomMonth + 1, randomDay),
69+
finish: new Date(randomYear + 1, randomMonth + 1, randomDay),
70+
effortDriven: (i % 5 === 0)
71+
};
72+
}
73+
74+
return mockDataset;
75+
}
76+
}

0 commit comments

Comments
 (0)