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

Table / EditableColumn: onEditComplete emitted event data is wrong #12822

Closed
Blackrobot96 opened this issue Mar 27, 2023 · 2 comments · Fixed by #12824
Closed

Table / EditableColumn: onEditComplete emitted event data is wrong #12822

Blackrobot96 opened this issue Mar 27, 2023 · 2 comments · Fixed by #12824
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@Blackrobot96
Copy link

Describe the bug

EditableColumn.closeEditingCell emits the onEditComplete event with the wrong data. The data of the newly clicked cell is emitted, instead of the completed cell. When leaving the cell with the data "OUTOFSTOCK" and clicking into the cell with the data "INSTOCK", the event.data of the onEditComplete function should be "OUTOFSTOCK", but is "INSTOCK" instead. The event.data is displayed below the table:
2023-03-27_14h53_54

Environment

Windows 11 & Stackblitz

Reproducer

https://stackblitz.com/edit/angular-jfoajd-hj13py?file=src/app/demo/table-cell-edit-demo.ts

Angular version

15.2.1

PrimeNG version

15.2.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.15.0

Browser(s)

No response

Steps to reproduce the behavior

Table with cell editing and a onEditComplete listener:
Print the event.data of the onEditComplete function.

  1. Click into an editable cell (e.g with data = A)
  2. Click into another editable cell (e.g with data = B)
    The onEditComplete function is going to print the data of the newly clicked cell. In this example it is going to print B.

Expected behavior

The event data should be the data of the completed cell.
For the example it should print A.

@Blackrobot96 Blackrobot96 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Mar 27, 2023
@Blackrobot96
Copy link
Author

Proposed change:
Change the emitted data in line

this.dt.onEditComplete.emit({ field: this.dt.editingCellField, data: this.data, originalEvent: event, index: this.dt.editingCellRowIndex });
from:
data: this.data
to:
data: this.dt.editingCellData

@Blackrobot96
Copy link
Author

As a workaround I currently override the closeEditingCell function in my polyfills file:

import { EditableColumn } from 'primeng/table';
import { DomHandler } from 'primeng/dom';
EditableColumn.prototype.closeEditingCell = function (completed: any, event: any): void {
    if (completed) {
        this.dt.onEditComplete.emit({ field: this.dt.editingCellField, data: this.dt.editingCellData, originalEvent: event, index: this.dt.editingCellRowIndex });
    } else {
        this.dt.onEditCancel.emit({ field: this.dt.editingCellField, data: this.dt.editingCellData, originalEvent: event, index: this.dt.editingCellRowIndex });

        this.dt.value.forEach((element) => {
            if (element[this.dt.editingCellField] === this.data) {
                element[this.dt.editingCellField] = this.dt.editingCellData;
            }
        });
    }

    DomHandler.removeClass(this.dt.editingCell, 'p-cell-editing');
    this.dt.editingCell = null;
    this.dt.editingCellData = null;
    this.dt.editingCellField = null;
    this.dt.unbindDocumentEditListener();

    if (this.dt.overlaySubscription) {
        this.dt.overlaySubscription.unsubscribe();
    }
}

volvachev added a commit to volvachev/primeng that referenced this issue Mar 27, 2023
@cetincakiroglu cetincakiroglu added this to the 15.3.1 milestone Mar 31, 2023
@cetincakiroglu cetincakiroglu added Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants