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

Commit 077b167

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
Add column inline onCellChange property.
1 parent 2e24bab commit 077b167

File tree

7 files changed

+60
-28
lines changed

7 files changed

+60
-28
lines changed

README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,19 @@ The goal is of course to be able to run SlickGrid within Angular 4+ but also to
1313
### NPM Package
1414
[Angular-Slickgrid on NPM](https://www.npmjs.com/package/angular-slickgrid)
1515

16-
<a name="wiki"></a>
17-
1816
## Wiki / Documentation
1917
The Wiki is where all the documentation and instructions will go, so please consult the [Angular-Validation - Wiki](https://github.com/ghiscoding/angular-slickgrid/wiki) before opening any issues. The [Wiki - HOWTO](https://github.com/ghiscoding/angular-slickgrid/wiki/HOWTO---Step-by-Step) is a great place to start with.
2018

2119

22-
<a name="main-features"></a>
23-
2420
## Main features
2521
You can see some screenshots below and the instructions down below.
2622

2723
This is a work in progress, but so far here are some of the features that `angular-slickgrid` brings (on top of Slickgrid itself):
2824
- Easier use of SlickGrid within `Angular` as it is just a component (simply pass a column definitions and a dataset and you're good to go)
2925
- Bootstrap Theme with SASS variables for extra customization (if you create a theme, then please make a PR)
3026
- Auto-resize (boolean flag), will resize the datagrid viewport with available space even on browser resize (basically takes available space of it's container)
31-
- Integrated Plugins.
32-
- Column Picker (show/hide any column by doing `right+click` in the header, click [here to see print screen](/screenshots/columnPicker.png)).
33-
- ... more to come
27+
- Inline Editors
28+
- Support all SlickGrid Plugins.
3429
- Server side (backend) Services (filtering, sorting, pagination)
3530
- [GraphQL](https://github.com/ghiscoding/Angular-Slikgrid/wiki/GraphQL)
3631
- [OData](https://github.com/ghiscoding/Angular-Slickgrid/wiki/OData)
@@ -40,20 +35,15 @@ This is a work in progress, but so far here are some of the features that `angul
4035
- Formatters (a few default ones were added, and you can easily create custom ones too)
4136
- Optimized DataView which brings a lot of functionalities (sort, grouping, and more)
4237
- even server side data is saved into the SlickGrid DataView
38+
- All the [SlickGrid Events](https://github.com/6pac/SlickGrid/wiki/Grid-Events) are supported, see the [Wiki](https://github.com/ghiscoding/Angular-Slickgrid/wiki/Grid-&-DataView-Events)
4339
- ... more to come
4440

45-
<a name="missing-features"></a>
46-
4741
## Missing features (planned items, not necessarily in order of execution)
4842
The following are SlickGrid features which are not yet included in this library but will be in the eventual future.
49-
- Inline Editors
5043
- Filters to support multi-select dropdown and eventually custom filters
51-
- Plugins (Header Menu, Grid Menu, Column Header Buttons)
52-
- Row selection, will probably provide a `onRowsChanged()` in the `gridOptions` object
53-
- Cell click, will probably provide a `onCellClicked()` in the `gridOptions` object
5444

5545
### License
56-
[MIT License](https://github.com/ghiscoding/Angular-Slickgrid/blob/master/LICENSE)
46+
[MIT License](LICENSE)
5747

5848
## Use it, like it?
5949
You like and use this great library `Angular-Slickgrid`? You can always upvote :star: and/or contribute :)

screenshots/column-picker.png

8.67 KB
Loading

screenshots/editors.png

20.5 KB
Loading

src/app/app.component.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.body-content {
22
margin-top: 60px;
33
}
4+
.red {
5+
color: red;
6+
}

src/app/examples/grid-editor.component.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Component, Input, OnInit } from '@angular/core';
22
import { Editors, Formatters } from './../modules/angular-slickgrid';
33
import { GridExtraUtils, ResizerService } from './../modules/angular-slickgrid/services';
4-
import { OnCellClickArgs, Column, FieldType, Formatter, GridOption } from './../modules/angular-slickgrid/models/index';
4+
import { OnEventArgs, Column, FieldType, Formatter, GridOption } from './../modules/angular-slickgrid/models/index';
55

66
@Component({
77
templateUrl: './grid-editor.component.html'
88
})
99
export class GridEditorComponent implements OnInit {
1010
title = 'Example 4: Editors';
11-
subTitle = `inline editors (not yet implement) and onCellClick editor (execute an action, e.g: open a modal window)`;
11+
subTitle = `Inline Editors and onCellClick Editor (execute an action, e.g: open a modal window)`;
1212

1313
columnDefinitions: Column[];
1414
gridOptions: GridOption;
@@ -26,24 +26,27 @@ export class GridEditorComponent implements OnInit {
2626
id: 'edit', field: 'id',
2727
formatter: Formatters.editIcon,
2828
maxWidth: 30,
29-
onCellClick: (args: OnCellClickArgs) => {
29+
onCellClick: (args: OnEventArgs) => {
3030
console.log(args);
31-
console.log(this);
3231
}
3332
},
3433
{
3534
id: 'delete', field: 'id',
3635
formatter: Formatters.deleteIcon,
3736
maxWidth: 30,
38-
onCellClick: (args: OnCellClickArgs) => {
37+
onCellClick: (args: OnEventArgs) => {
3938
console.log(args);
40-
console.log(this);
4139
}
4240
},
4341
{ id: 'title', name: 'Title', field: 'title', sortable: true, type: FieldType.string, editor: Editors.longText },
44-
{ id: 'duration', name: 'Duration (days)', field: 'duration', sortable: true, type: FieldType.number, editor: Editors.text },
42+
{ id: 'duration', name: 'Duration (days)', field: 'duration', sortable: true, type: FieldType.number, editor: Editors.text,
43+
onCellChange: (args: OnEventArgs) => {
44+
alert('onCellChange directly attached to the column definition');
45+
console.log(args);
46+
}
47+
},
4548
{ id: 'complete', name: '% Complete', field: 'percentComplete', formatter: Formatters.percentCompleteBar, type: FieldType.number, editor: Editors.integer },
46-
{ id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso, sortable: true, type: FieldType.date, editor: Editors.date },
49+
{ id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso, sortable: true, type: FieldType.date/*, editor: Editors.date*/ },
4750
{ id: 'finish', name: 'Finish', field: 'finish', formatter: Formatters.dateIso, sortable: true, type: FieldType.date },
4851
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', formatter: Formatters.checkmark, type: FieldType.number, editor: Editors.checkbox }
4952
];
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { GridOption } from './gridOption.interface';
2+
import { Column } from './column.interface';
3+
4+
export interface OnEventArgs {
5+
columnDef: Column;
6+
dataContext: any;
7+
dataView: any; // TODO replace by a DataView interface
8+
grid: any; // TODO replace by a SlickGrid interface
9+
gridDefinition: GridOption;
10+
}

src/app/modules/angular-slickgrid/services/gridEvent.service.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OnCellClickArgs, CellArgs, GridOption } from './../models/index';
1+
import { OnEventArgs, CellArgs, GridOption } from './../models/index';
22

33
export class GridEventService {
44
/* OnMouseHover (Enter/Leave) Events */
@@ -16,6 +16,32 @@ export class GridEventService {
1616
});
1717
}
1818

19+
/* OnCellChange Event */
20+
attachOnCellChange(grid: any, gridOptions: GridOption, dataView: any) {
21+
// subscribe to this Slickgrid event of onCellChange
22+
grid.onCellChange.subscribe((e: Event, args: CellArgs) => {
23+
if (!e || !args || !args.grid || args.cell === undefined || !args.grid.getColumns || !args.grid.getDataItem) {
24+
return;
25+
}
26+
const column = args.grid.getColumns()[args.cell];
27+
28+
// if the column definition has a onCellChange property (a callback function), then run it
29+
if (typeof column.onCellChange === 'function') {
30+
// add to the output gridOptions & dataView since we'll need them inside the AJAX column.onCellChange
31+
const returnedArgs: OnEventArgs = {
32+
dataView,
33+
gridDefinition: gridOptions,
34+
grid,
35+
columnDef: column,
36+
dataContext: args.grid.getDataItem(args.row)
37+
};
38+
39+
// finally call up the Slick.column.onCellChanges.... function
40+
column.onCellChange(returnedArgs);
41+
// e.stopImmediatePropagation();
42+
}
43+
});
44+
}
1945
/* OnClick Event */
2046
attachOnClick(grid: any, gridOptions: GridOption, dataView: any) {
2147

@@ -25,19 +51,19 @@ export class GridEventService {
2551
}
2652
const column = args.grid.getColumns()[args.cell];
2753

28-
// so if the columns definition does have an column.onCellClick property (a function attached), then run it
54+
// if the column definition has a onCellClick property (a callback function), then run it
2955
if (typeof column.onCellClick === 'function') {
30-
// attach both "this._gridOptions" and "_slickDataViewObj" since we'll need them inside the AJAX column.onClick
31-
const onCellClickArgs: OnCellClickArgs = {
56+
// add to the output gridOptions & dataView since we'll need them inside the AJAX column.onClick
57+
const returnedArgs: OnEventArgs = {
3258
dataView,
3359
gridDefinition: gridOptions,
3460
grid,
3561
columnDef: column,
3662
dataContext: args.grid.getDataItem(args.row)
3763
};
3864

39-
// finally call up the Slick.column.onClicks.... function
40-
column.onCellClick(onCellClickArgs);
65+
// finally call up the Slick.column.onCellClick.... function
66+
column.onCellClick(returnedArgs);
4167
e.stopImmediatePropagation();
4268
}
4369

0 commit comments

Comments
 (0)