Skip to content

Commit

Permalink
Fixed #2104
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Mar 27, 2017
1 parent 66ebcda commit 9bf8a35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion components/common/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ export class ColumnEditorTemplateLoader implements OnInit, OnDestroy {
@Input() column: any;

@Input() rowData: any;

@Input() rowIndex: any;

view: EmbeddedViewRef<any>;

Expand All @@ -271,7 +273,8 @@ export class ColumnEditorTemplateLoader implements OnInit, OnDestroy {
ngOnInit() {
this.view = this.viewContainer.createEmbeddedView(this.column.editorTemplate, {
'\$implicit': this.column,
'rowData': this.rowData
'rowData': this.rowData,
'rowIndex': this.rowIndex
});
}

Expand Down
12 changes: 6 additions & 6 deletions components/datatable/datatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ export class ColumnFooters {
</span>
<div class="ui-cell-editor" *ngIf="col.editable">
<input *ngIf="!col.editorTemplate" type="text" [(ngModel)]="rowData[col.field]" required="true"
(keydown)="dt.onCellEditorKeydown($event, col, rowData, colIndex)" class="ui-inputtext ui-widget ui-state-default ui-corner-all"/>
<p-columnEditorTemplateLoader *ngIf="col.editorTemplate" [column]="col" [rowData]="rowData"></p-columnEditorTemplateLoader>
(keydown)="dt.onCellEditorKeydown($event, col, rowData, colIndex, rowIndex)" class="ui-inputtext ui-widget ui-state-default ui-corner-all"/>
<p-columnEditorTemplateLoader *ngIf="col.editorTemplate" [column]="col" [rowData]="rowData" [rowIndex]="rowIndex"></p-columnEditorTemplateLoader>
</div>
<a href="#" *ngIf="col.expander" (click)="dt.toggleRow(rowData,$event)">
<span class="ui-row-toggler fa fa-fw ui-c" [ngClass]="{'fa-chevron-circle-down':dt.isRowExpanded(rowData), 'fa-chevron-circle-right': !dt.isRowExpanded(rowData)}"></span>
Expand Down Expand Up @@ -1542,21 +1542,21 @@ export class DataTable implements AfterViewChecked,AfterViewInit,AfterContentIni
this.domHandler.removeClass(cell, 'ui-cell-editing');
}

onCellEditorKeydown(event, column: Column, rowData: any, colIndex: number) {
onCellEditorKeydown(event, column: Column, rowData: any, colIndex: number, rowIndex: number) {
if(this.editable) {
this.onEdit.emit({originalEvent: event, column: column, data: rowData});
this.onEdit.emit({originalEvent: event, column: column, data: rowData, index: rowIndex});

//enter
if(event.keyCode == 13) {
this.onEditComplete.emit({column: column, data: rowData});
this.onEditComplete.emit({column: column, data: rowData, index: rowIndex});
this.renderer.invokeElementMethod(event.target, 'blur');
this.switchCellToViewMode(event.target);
event.preventDefault();
}

//escape
else if(event.keyCode == 27) {
this.onEditCancel.emit({column: column, data: rowData});
this.onEditCancel.emit({column: column, data: rowData, index: rowIndex});
this.renderer.invokeElementMethod(event.target, 'blur');
this.switchCellToViewMode(event.target);
event.preventDefault();
Expand Down
9 changes: 6 additions & 3 deletions showcase/demo/datatable/datatabledemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -1273,19 +1273,22 @@ <h3>Events</h3>
<td>onEdit</td>
<td>event.originalEvent: Browser event
event.column: Column object of the cell<br>
event.data: Row data</td>
event.data: Row data <br />
event.index: Row index</td>
<td>Callback to invoke when cell data is being edited.</td>
</tr>
<tr>
<td>onEditComplete</td>
<td>event.column: Column object of the cell<br>
event.data: Row data</td>
event.data: Row data <br />
event.index: Row index</td>
<td>Callback to invoke when cell edit is completed.</td>
</tr>
<tr>
<td>onEditCancel</td>
<td>event.column: Column object of the cell<br>
event.data: Row data</td>
event.data: Row data <br />
event.index: Row index</td>
<td>Callback to invoke when cell edit is cancelled with escape key.</td>
</tr>
<tr>
Expand Down

0 comments on commit 9bf8a35

Please sign in to comment.