Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eventService): use grid.getOptions for gridDefinition #51

Merged
merged 2 commits into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aurelia-slickgrid/src/aurelia-slickgrid/aurelia-slickgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ export class AureliaSlickgridCustomElement {
});

// on cell click, mainly used with the columnDef.action callback
this.gridEventService.attachOnCellChange(grid, this.gridOptions, dataView);
this.gridEventService.attachOnClick(grid, this.gridOptions, dataView);
this.gridEventService.attachOnCellChange(grid, dataView);
this.gridEventService.attachOnClick(grid, dataView);

this._eventHandler.subscribe(dataView.onRowCountChanged, (e: any, args: any) => {
grid.updateRowCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export class GridEventService {
private _eventHandler: any = new Slick.EventHandler();

/* OnCellChange Event */
attachOnCellChange(grid: any, gridOptions: GridOption, dataView: any) {
attachOnCellChange(grid: any, dataView: any) {
// subscribe to this Slickgrid event of onCellChange
this._eventHandler.subscribe(grid.onCellChange, (e: Event, args: CellArgs) => {
if (!e || !args || !args.grid || args.cell === undefined || !args.grid.getColumns || !args.grid.getDataItem) {
if (!e || !args || !grid || args.cell === undefined || !grid.getColumns || !grid.getDataItem) {
return;
}
const column = args.grid.getColumns()[args.cell];
const column = grid.getColumns()[args.cell];

// if the column definition has a onCellChange property (a callback function), then run it
if (typeof column.onCellChange === 'function') {
Expand All @@ -22,10 +22,10 @@ export class GridEventService {
row: args.row,
cell: args.cell,
dataView,
gridDefinition: gridOptions,
gridDefinition: grid.getOptions(),
grid,
columnDef: column,
dataContext: args.grid.getDataItem(args.row)
dataContext: grid.getDataItem(args.row)
};

// finally call up the Slick.column.onCellChanges.... function
Expand All @@ -35,12 +35,12 @@ export class GridEventService {
});
}
/* OnClick Event */
attachOnClick(grid: any, gridOptions: GridOption, dataView: any) {
attachOnClick(grid: any, dataView: any) {
this._eventHandler.subscribe(grid.onClick, (e: Event, args: CellArgs) => {
if (!e || !args || !args.grid || args.cell === undefined || !args.grid.getColumns || !args.grid.getDataItem) {
if (!e || !args || !grid || args.cell === undefined || !grid.getColumns || !grid.getDataItem) {
return;
}
const column = args.grid.getColumns()[args.cell];
const column = grid.getColumns()[args.cell];

// if the column definition has a onCellClick property (a callback function), then run it
if (typeof column.onCellClick === 'function') {
Expand All @@ -49,10 +49,10 @@ export class GridEventService {
row: args.row,
cell: args.cell,
dataView,
gridDefinition: gridOptions,
gridDefinition: grid.getOptions(),
grid,
columnDef: column,
dataContext: args.grid.getDataItem(args.row)
dataContext: grid.getDataItem(args.row)
};

// finally call up the Slick.column.onCellClick.... function
Expand Down
2 changes: 1 addition & 1 deletion aurelia-slickgrid/src/examples/slickgrid/example3.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2>${title}</h2>

<div class="col-sm-8">
<div class="alert alert-info" show.bind="updatedObject">
<strong>Update Object:</strong> ${updatedObject | stringify}
<strong>Updated Item:</strong> ${updatedObject | stringify}
</div>
<div class="alert alert-warning" show.bind="alertWarning">
<strong></strong> ${alertWarning}
Expand Down
20 changes: 12 additions & 8 deletions aurelia-slickgrid/src/examples/slickgrid/example3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,25 @@ export class Example3 {
formatter: Formatters.deleteIcon,
minWidth: 30,
maxWidth: 30,
// use onCellClick OR grid.onClick.subscribe which you can see down below
/*
onCellClick: (args: OnEventArgs) => {
console.log(args);
this.alertWarning = `Deleting: ${args.dataContext.title}`;
}
*/
// use onCellClick OR grid.onClick.subscribe which you can see down below
/*
onCellClick: (args: OnEventArgs) => {
console.log(args);
this.alertWarning = `Deleting: ${args.dataContext.title}`;
}
*/
}, {
id: 'title',
name: 'Title',
field: 'title',
sortable: true,
type: FieldType.string,
editor: Editors.longText,
minWidth: 100
minWidth: 100,
onCellChange: (args: OnEventArgs) => {
console.log(args);
this.alertWarning = `Updated Title: ${args.dataContext.title}`;
}
}, {
id: 'duration',
name: 'Duration (days)',
Expand Down