Skip to content

Commit 3330525

Browse files
authored
feat(angular): add all event Types to support Strict Templates (#2243)
* feat(angular): add all event Types to support Strict Templates
1 parent b8cfacd commit 3330525

22 files changed

+490
-412
lines changed

frameworks/angular-slickgrid/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ export class GridComponent implements OnInit {
6767
[dataset]="dataset">
6868
</angular-slickgrid>
6969
```
70-
### Troubleshooting
71-
72-
> [!WARNING]
73-
> Because of its use of native Custom Event, this project **does not** work well with `strictTemplates`, so please make sure to either disable `strictTemplates` or cast your event as `any` (see this [discussion](https://github.com/ghiscoding/Angular-Slickgrid/discussions/815) for more info)
7470

7571
### Styling Themes
7672

@@ -143,7 +139,3 @@ Angular-Slickgrid uses [`ngx-translate`](https://github.com/ngx-translate/core)
143139

144140
### Tested with [Vitest](https://vitest.dev/) (Unit Tests) - [Cypress](https://www.cypress.io/) (E2E Tests)
145141
Slickgrid-Universal & Angular-Slickgrid both have **100%** Unit Test Coverage and also every Angular-Slickgrid Examples are fully tested with [Cypress](https://www.cypress.io/) as E2E tests.
146-
147-
## Troubleshooting Section
148-
149-
- [`strictTemplates` error](https://ghiscoding.gitbook.io/angular-slickgrid/getting-started/troubleshooting#stricttemplates-error)

frameworks/angular-slickgrid/docs/TOC.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
## Events
3838

39-
* [Available events](events/Available-Events.md)
40-
* [On Events](events/Grid-&-DataView-Events.md)
39+
* [Available events](events/available-events.md)
40+
* [On Events](events/grid-and-dataview-events.md)
4141

4242
## Slick Grid/DataView Objects
4343
* [Slick Grid/DataView Objects](slick-grid-dataview-objects/slickgrid-dataview-objects.md)

frameworks/angular-slickgrid/docs/events/Available-Events.md renamed to frameworks/angular-slickgrid/docs/events/available-events.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ handleOnHeaderMenuCommand(e) {
101101
- `onHeaderMenuBeforeMenuShow`
102102
- `onHeaderMenuAfterMenuShow`
103103

104+
#### Export Services
105+
- `onAfterExportToExcel`
106+
- `onBeforeExportToExcel`
107+
- `onBeforeExportToTextFile`
108+
- `onAfterExportToTextFile`
109+
104110
#### Filter Service
105111
- `onBeforeFilterClear`
106112
- `onBeforeSearchChange`

frameworks/angular-slickgrid/docs/events/Grid-&-DataView-Events.md renamed to frameworks/angular-slickgrid/docs/events/grid-and-dataview-events.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -179,33 +179,3 @@ export class MyApp {
179179
}
180180
}
181181
```
182-
183-
### Error thrown in the IDE when using `strictTemplates`
184-
You might get some error thrown in your editor by the Angular-Language-Service, the error might 1 of these
185-
```shell
186-
Event onAngularGridCreated is not emitted by any applicable directives nor by angular-slickgrid element
187-
```
188-
or
189-
```shell
190-
error TS2339: Property 'detail' does not exist on type 'Event'.
191-
```
192-
There are 3 possible solutions to fix this issue
193-
1. disabled `strictTemplates`
194-
2. define argument type as `Event` to avoid error then later cast it as a `CustomEvent`
195-
```ts
196-
angularGridReady(event: Event) {
197-
this.angularGrid = (event as CustomEvent).detail as AngularGridInstance;
198-
}
199-
```
200-
3. use `$any()` in the View
201-
```html
202-
<angular-slickgrid gridId="grid1"
203-
[columns]="columnDefinitions"
204-
[options]="gridOptions"
205-
[dataset]="dataset"
206-
(onAngularGridCreated)="angularGridReady($any($event).detail)">
207-
</angular-slickgrid>
208-
```
209-
You can read more on the subject at:
210-
- Stack Overflow question [Cannot use onAngularGridCreated emitter](https://stackoverflow.com/questions/71156193/cannot-use-onangulargridcreated-emitter/71245004#71245004)
211-
- Discussion [#815](https://github.com/ghiscoding/angular-slickgrid/discussions/815)

frameworks/angular-slickgrid/oxlintrc-angular.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@
77
},
88
"plugins": ["oxc", "regex", "typescript", "vitest"],
99
"jsPlugins": ["@angular-eslint/eslint-plugin"],
10-
"ignorePatterns": [
11-
"**/*.spec.ts",
12-
"**/*.cy.ts",
13-
".angular/*",
14-
"dist/",
15-
"coverage/",
16-
"test/",
17-
"**/environment.*.ts",
18-
"**/grid-remote.component.ts",
19-
"**/public_api.ts"
20-
],
10+
"ignorePatterns": ["**/*.spec.ts", "**/*.cy.ts", ".angular/*", "dist/", "coverage/", "test/", "**/environment.*.ts", "**/public_api.ts"],
2111
"overrides": [
2212
{
2313
"files": ["**/*.ts"],

frameworks/angular-slickgrid/src/demos/examples/example05.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AngularSlickgridModule,
77
Filters,
88
OperatorType,
9+
PaginationMetadata,
910
type AngularGridInstance,
1011
type Column,
1112
type GridOption,
@@ -443,7 +444,7 @@ export class Example5Component implements OnInit {
443444
return true;
444445
}
445446

446-
handleOnBeforePaginationChange(_e: Event) {
447+
handleOnBeforePaginationChange(_e: CustomEvent<PaginationMetadata>) {
447448
// e.preventDefault();
448449
// return false;
449450
return true;

frameworks/angular-slickgrid/src/demos/examples/example19-rowdetail.component.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ import { FormsModule } from '@angular/forms';
44
import type { SlickDataView, SlickGrid } from '../../library';
55
import type { Example19Component } from './example19.component';
66

7+
interface ItemDetail {
8+
rowId: string;
9+
duration: number;
10+
percentComplete: number;
11+
reporter: string;
12+
start: Date;
13+
finish: Date;
14+
effortDriven: boolean;
15+
assignee: string;
16+
title: string;
17+
}
18+
719
@Component({
820
styles: ['.detail-label { display: inline-flex; align-items: center; gap: 4px; padding: 4px; }', 'label { font-weight: 600; }'],
921
templateUrl: './example19-rowdetail.component.html',
10-
imports: [FormsModule, DecimalPipe, DatePipe],
22+
imports: [DatePipe, DecimalPipe, FormsModule],
1123
})
1224
export class Example19RowDetailComponent {
13-
model!: {
14-
duration: Date;
15-
percentComplete: number;
16-
reporter: string;
17-
start: Date;
18-
finish: Date;
19-
effortDriven: boolean;
20-
assignee: string;
21-
title: string;
22-
};
25+
model: ItemDetail = {} as ItemDetail;
2326

2427
// you also have access to the following objects (it must match the exact property names shown below)
2528
addon: any; // row detail addon instance
@@ -30,15 +33,15 @@ export class Example19RowDetailComponent {
3033
// NOTE that you MUST provide it through the "parentRef" property in your "rowDetail" grid options
3134
parentRef!: Example19Component;
3235

33-
alertAssignee(name: string) {
36+
alertAssignee(name?: string) {
3437
if (typeof name === 'string') {
3538
alert(`Assignee on this task is: ${name.toUpperCase()}`);
3639
} else {
3740
alert('No one is assigned to this task.');
3841
}
3942
}
4043

41-
deleteRow(model: any) {
44+
deleteRow(model: ItemDetail) {
4245
if (confirm(`Are you sure that you want to delete ${model.title}?`)) {
4346
// you first need to collapse all rows (via the 3rd party addon instance)
4447
this.addon.collapseAll();
@@ -50,7 +53,7 @@ export class Example19RowDetailComponent {
5053
}
5154
}
5255

53-
callParentMethod(model: any) {
56+
callParentMethod(model: ItemDetail) {
5457
this.parentRef.showFlashMessage(`We just called Parent Method from the Row Detail Child Component on ${model.title}`);
5558
}
5659
}

frameworks/angular-slickgrid/src/demos/examples/example27.component.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,9 @@ <h2>
132132
(onFilterCleared)="hideSpinner()"
133133
(onBeforeSortChange)="showSpinner()"
134134
(onSortChanged)="hideSpinner()"
135-
(onBeforeToggleTreeCollapse)="showSpinner()"
136-
(onToggle-tree-collapsed)="hideSpinner()"
137-
(onTree-full-toggle-start)="showSpinner()"
138-
(onTree-full-toggle-end)="handleOnTreeFullToggleEnd($event.detail)"
139-
(onTree-item-toggled)="handleOnTreeItemToggled($event.detail)"
135+
(onTreeFullToggleStart)="showSpinner()"
136+
(onTreeFullToggleEnd)="handleOnTreeFullToggleEnd($event.detail)"
137+
(onTreeItemToggled)="handleOnTreeItemToggled($event.detail)"
140138
>
141139
</angular-slickgrid>
142140
</div>

frameworks/angular-slickgrid/src/demos/examples/example30.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,8 @@ export class Example30Component implements OnDestroy, OnInit {
617617
return false;
618618
}
619619

620-
handleItemDeleted(itemId: string) {
621-
console.log('item deleted with id:', itemId);
620+
handleItemDeleted(itemIds: string[]) {
621+
console.log('item deleted with ids:', itemIds);
622622
}
623623

624624
handleOnBeforeEditCell(e: Event, args: any) {

frameworks/angular-slickgrid/src/demos/examples/example32.component.ts

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,11 @@ import {
1717
type GridOption,
1818
type LongTextEditorOption,
1919
type SearchTerm,
20-
type SlickGrid,
2120
type VanillaCalendarOption,
2221
} from '../../library';
2322

2423
const URL_COUNTRIES_COLLECTION = 'assets/data/countries.json';
2524

26-
/**
27-
* Check if the current item (cell) is editable or not
28-
* @param {*} dataContext - item data context object
29-
* @param {*} columnDef - column definition
30-
* @param {*} grid - slickgrid grid object
31-
* @returns {boolean} isEditable
32-
*/
33-
function checkItemIsEditable(dataContext: any, columnDef: Column, grid: SlickGrid) {
34-
const gridOptions = grid && grid.getOptions && grid.getOptions();
35-
const hasEditor = columnDef.editor;
36-
const isGridEditable = gridOptions.editable;
37-
let isEditable = !!(isGridEditable && hasEditor);
38-
39-
if (dataContext && columnDef && gridOptions && gridOptions.editable) {
40-
switch (columnDef.id) {
41-
case 'finish':
42-
isEditable = !!dataContext?.completed;
43-
break;
44-
}
45-
}
46-
return isEditable;
47-
}
48-
4925
const customEditableInputFormatter: Formatter = (_row, _cell, value, columnDef, _dataContext, grid) => {
5026
const gridOptions = grid && grid.getOptions && grid.getOptions();
5127
const isEditableLine = gridOptions.editable && columnDef.editor;
@@ -607,44 +583,6 @@ export class Example32Component implements OnInit {
607583
return tmpArray;
608584
}
609585

610-
handleValidationError(_e: Event, args: any) {
611-
if (args.validationResults) {
612-
alert(args.validationResults.msg);
613-
}
614-
return false;
615-
}
616-
617-
handleItemDeleted(_e: Event, args: any) {
618-
console.log('item deleted with id:', args.itemId);
619-
}
620-
621-
handleOnBeforeEditCell(e: Event, args: any) {
622-
const { column, item, grid } = args;
623-
624-
if (column && item) {
625-
if (!checkItemIsEditable(item, column, grid)) {
626-
e.preventDefault(); // OR eventData.preventDefault();
627-
return false;
628-
}
629-
}
630-
return false;
631-
}
632-
633-
handleOnCellChange(_e: Event, args: any) {
634-
const dataContext = args?.item;
635-
636-
// when the field "completed" changes to false, we also need to blank out the "finish" date
637-
if (dataContext && !dataContext.completed) {
638-
dataContext.finish = null;
639-
this.angularGrid.gridService.updateItem(dataContext);
640-
}
641-
}
642-
643-
handlePaginationChanged() {
644-
this.removeAllUnsavedStylingFromCell();
645-
this.renderUnsavedStylingOnAllVisibleCells();
646-
}
647-
648586
handleDefaultResizeColumns() {
649587
// just for demo purposes, set it back to its original width
650588
const columns = this.angularGrid.slickGrid.getColumns() as Column[];

0 commit comments

Comments
 (0)