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

Commit d1ee6cb

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
Add row and cell in the column definition onCellChange
1 parent cc386d2 commit d1ee6cb

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export class GridEditorComponent implements OnInit {
88
title = 'Example 3: Editors';
99
subTitle = `
1010
Grid with Inline Editors and onCellClick actions (<a href="https://github.com/ghiscoding/Angular-Slickgrid/wiki/Editors">Wiki link</a>).
11+
<ul>
12+
<li>When using "enableCellNavigation: true", clicking on a cell will automatically make it active &amp; selected.
13+
<ul><li>If you don't want this behavior, then you should disable "enableCellNavigation"</li></ul>
14+
<li>Inline Editors requires "enableCellNavigation: true" (not sure why though)</li>
15+
</ul>
1116
`;
1217

1318
columnDefinitions: Column[];
@@ -27,25 +32,24 @@ export class GridEditorComponent implements OnInit {
2732
formatter: Formatters.editIcon,
2833
minWidth: 30,
2934
maxWidth: 30,
30-
/*
3135
// use onCellClick OR grid.onClick.subscribe which you can see down below
3236
onCellClick: (args: OnEventArgs) => {
3337
console.log(args);
3438
alert(`Editing: ${args.dataContext.title}`);
35-
}*/
39+
this.gridExtraService.highlightRow(args.row, 1500);
40+
this.gridExtraService.setSelectedRow(args.row);
41+
}
3642
},
3743
{
3844
id: 'delete', field: 'id',
3945
formatter: Formatters.deleteIcon,
4046
minWidth: 30,
4147
maxWidth: 30,
42-
/*
4348
// use onCellClick OR grid.onClick.subscribe which you can see down below
4449
onCellClick: (args: OnEventArgs) => {
4550
console.log(args);
4651
alert(`Deleting: ${args.dataContext.title}`);
4752
}
48-
*/
4953
},
5054
{ id: 'title', name: 'Title', field: 'title', sortable: true, type: FieldType.string, editor: Editors.longText },
5155
{ id: 'duration', name: 'Duration (days)', field: 'duration', sortable: true, type: FieldType.number, editor: Editors.text,
@@ -102,6 +106,9 @@ export class GridEditorComponent implements OnInit {
102106
this.updatedObject = args.item;
103107
this.resizer.resizeGrid(this.gridObj, this.gridOptions, 10);
104108
});
109+
110+
// You could also subscribe to grid.onClick
111+
// Note that if you had already setup "onCellClick" in the column definition, you cannot use grid.onClick
105112
grid.onClick.subscribe((e, args) => {
106113
const column = GridExtraUtils.getColumnDefinitionAndData(args);
107114
console.log('onClick', args, column);

src/app/modules/angular-slickgrid/models/onEventArgs.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { GridOption } from './gridOption.interface';
22
import { Column } from './column.interface';
33

44
export interface OnEventArgs {
5+
row: number;
6+
cell: number;
57
columnDef: Column;
68
dataContext: any;
79
dataView: any; // TODO replace by a DataView interface

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export class GridEventService {
1414
if (typeof column.onCellChange === 'function') {
1515
// add to the output gridOptions & dataView since we'll need them inside the AJAX column.onCellChange
1616
const returnedArgs: OnEventArgs = {
17+
row: args.row,
18+
cell: args.cell,
1719
dataView,
1820
gridDefinition: gridOptions,
1921
grid,
@@ -40,6 +42,8 @@ export class GridEventService {
4042
if (typeof column.onCellClick === 'function') {
4143
// add to the output gridOptions & dataView since we'll need them inside the AJAX column.onClick
4244
const returnedArgs: OnEventArgs = {
45+
row: args.row,
46+
cell: args.cell,
4347
dataView,
4448
gridDefinition: gridOptions,
4549
grid,

0 commit comments

Comments
 (0)