Invoke keyboardEvent manually on button click in Primeng

UI Components for Angular
Post Reply
dermaga
Posts: 3
Joined: 27 Jan 2017, 16:07

19 Mar 2018, 16:06

I using the p-table component with editable cells. Each cell shows a button if the cell is in edit mode. If you go out of the cell by pressing esc or return the save button is not visable.
I am invoking a keydown event on a button click like this:

Code: Select all

const escapeEvent: any = document.createEvent('Event');
escapeEvent.keyCode  = 27; // escape
escapeEvent.initEvent('keydown', true, true);

td.dispatchEvent(escapeEvent);
It invokes the default primeng code wich is this:

Code: Select all

@HostListener('keydown', ['$event'])
    onKeyDown(event: KeyboardEvent) {
        if (this.isEnabled()) {
            //enter
            if (event.keyCode == 13) {
                if (this.isValid()) {
                    this.domHandler.removeClass(this.dt.editingCell, 'ui-editing-cell');
                    this.dt.editingCell = null;
                    this.dt.onEditComplete.emit({ field: this.field, data: this.data });
                }

                event.preventDefault();
            }

            //escape
            else if (event.keyCode == 27) {
                if (this.isValid()) {
                    this.domHandler.removeClass(this.dt.editingCell, 'ui-editing-cell');
                    this.dt.editingCell = null;
                    this.dt.onEditCancel.emit({ field: this.field, data: this.data });
                }

                event.preventDefault();
            }

            //tab
            else if (event.keyCode == 9) {
                if (event.shiftKey)
                    this.moveToPreviousCell(event);
                else
                    this.moveToNextCell(event);
            }
        }
    }
source code from primeng table.ts - https://github.com/primefaces/primeng/b ... e.ts#L2388

The actuell cell which I am currently editing should close and it should switch to the output template. The problem is that if I invoke the event manually only the focus is lost but the cell is still in edit mode.

Why is it still in edit mode and not in text ouput mode?

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests