-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ROU-4186: New block for the click event on the grid (#328)
* Add GridOnCellClickEvent * Create ClickEvent feature * Add dispose method in ClickEvent * Remove JSON stringify from OnCellClickEvent trigger * Fix eslint errors
- Loading branch information
1 parent
20a0b09
commit fba3b01
Showing
7 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/OSFramework/DataGrid/Event/Grid/GridOnCellClickEvent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
namespace OSFramework.DataGrid.Event.Grid { | ||
/** | ||
*Class that represents the Cell Click Change event. | ||
* | ||
* @export | ||
* @class GridOnCellClickEvent | ||
* @extends {AbstractGridEvent} | ||
*/ | ||
export class GridOnCellClickEvent extends AbstractGridEvent { | ||
/** | ||
* Method that will trigger the event with the correct parameters. | ||
* | ||
* @param gridObj grid that is raising the event | ||
* @param gridID id of the grid that is raising the event | ||
* @param columnWidgetId id of the column that is raising the event | ||
* @param rowNumber id of the row number that is raising the event | ||
* @param line data of the row that is raising the event | ||
*/ | ||
public trigger( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
gridObj: OSFramework.DataGrid.Grid.IGrid, | ||
gridID: string, | ||
columnWidgetId: string, | ||
rowNumber: number, | ||
binding: string, | ||
line: string | ||
): void { | ||
this.handlers | ||
.slice(0) | ||
.forEach((h) => | ||
Helper.AsyncInvocation( | ||
h, | ||
gridID, | ||
columnWidgetId, | ||
rowNumber, | ||
binding, | ||
line | ||
) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
namespace OSFramework.DataGrid.Feature { | ||
export interface IClickEvent { | ||
/** | ||
* Responsible for add the cell event listener handler | ||
* @param {function} callback | ||
*/ | ||
setCellClickEvent( | ||
callback: (this: HTMLElement, ev: MouseEvent) => void | ||
): void; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
namespace Providers.DataGrid.Wijmo.Feature { | ||
export class ClickEvent | ||
implements | ||
OSFramework.DataGrid.Feature.IClickEvent, | ||
OSFramework.DataGrid.Interface.IBuilder, | ||
OSFramework.DataGrid.Interface.IDisposable | ||
{ | ||
protected _grid: Providers.DataGrid.Wijmo.Grid.IGridWijmo; | ||
|
||
constructor( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
grid: Providers.DataGrid.Wijmo.Grid.IGridWijmo | ||
) { | ||
this._grid = grid; | ||
} | ||
|
||
private _raiseCellClickEvent(e: MouseEvent) { | ||
const ht = this._grid.provider.hitTest(e); | ||
if (ht.cellType === wijmo.grid.CellType.Cell) { | ||
const column = this._grid.getColumns()[ht.col]; | ||
const columnWidgetId = column.widgetId; | ||
const rowNumber = ht.row; | ||
const binding = column.config.binding; | ||
const line = _.cloneDeep( | ||
this._grid.provider.rows[rowNumber].dataItem | ||
); | ||
this._grid.rowMetadata.clear(line); | ||
|
||
this._grid.gridEvents.trigger( | ||
OSFramework.DataGrid.Event.Grid.GridEventType.OnCellClick, | ||
this._grid, | ||
columnWidgetId, | ||
rowNumber, | ||
binding, | ||
JSON.stringify( | ||
this._grid.isSingleEntity | ||
? OSFramework.DataGrid.Helper.Flatten(line) | ||
: line | ||
) | ||
); | ||
} | ||
} | ||
|
||
public build(): void { | ||
this.setCellClickEvent(this._raiseCellClickEvent.bind(this)); | ||
} | ||
|
||
public dispose(): void { | ||
this.removeCellClickEvent(this._raiseCellClickEvent.bind(this)); | ||
} | ||
|
||
public removeCellClickEvent(callback: (ev: MouseEvent) => void): void { | ||
this._grid.provider.removeEventListener( | ||
this._grid.provider.hostElement, | ||
'click', | ||
callback | ||
); | ||
} | ||
|
||
public setCellClickEvent(callback: (ev: MouseEvent) => void): void { | ||
this._grid.provider.addEventListener( | ||
this._grid.provider.hostElement, | ||
'click', | ||
callback | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters