primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Programmatically start edit mode in TurboTable

Open grzegorzbernat opened this issue 8 years ago • 7 comments

I'm submitting a ... (check one with "x")

[ ] bug report => Search github for a similar issue or PR before submitting
[X] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Current behavior Currently TurboTable in PrimeNG has ability to enable edit mode by adding pEditableColumn directive into table cell and using p-cellEditor to create suitable template for preview and edit view. By default, only way to enter edit mode is single click.

Expected behavior Add attribute or event to enable edit mode programatically, for example after double click.

What is the motivation / use case for changing the behavior? It should extend functionalities of TurboTable.

grzegorzbernat avatar Apr 16 '18 08:04 grzegorzbernat

I would like to recommend this feature

avarndell avatar Apr 17 '18 10:04 avarndell

I also think this feature is very interesting. It will give a lot of added value to the component

crissty avatar Sep 07 '18 11:09 crissty

Edit on double click would be great, it would allow users to select the row on single click, for example if that action then caused other events to fire off, and then a double click to edit.

jperuggia avatar Sep 11 '18 21:09 jperuggia

We also want to use double click for edit mode, because we use single click for cell selection. Right now my collegue hacked it like this:

Create a onCellClick event where we set this.treeGrid.editingCell to null to prevent single click from going into edit mode:

  @ViewChild('treeGrid') treeGrid: TreeTable;

  public onCellClick(row: string, col: string): void {
    this.treeGrid.editingCell = null;
  }

Added onCellClick and dvmTreegridEditColumn directive to our <td>:

      <td
        class="cell"
        *ngFor="let col of columns; let i = index"
        (click)="onCellClick(rowData['id'], col.colId)"
        ttEditableColumn
        vmTreegridEditColumn
      >

The directive that 'clicks' the cell on the dblclick event:

import { Directive, HostListener } from '@angular/core';
import { TTEditableColumn } from 'primeng/treetable';

@Directive({
  selector: '[vmTreegridEditColumn]'
})
export class TreegridEditColumnDirective {
  constructor(private _column2Edit: TTEditableColumn) { }
  @HostListener('dblclick', ['$event'])
  onDblClick(e: MouseEvent) {
    this._column2Edit.onClick(e);
  }
}

It's not pretty and we are probably going to refactor it, but for now this works. We would very much like to see the ability to use double click or any other event to become a standard feature.

[edit] If it matters: we are using a p-treeTable, not the p-table.

kayvanbree avatar Mar 25 '19 15:03 kayvanbree

here's what I did for table

import { OnInit, Input, Directive, HostListener } from '@angular/core';
import { EditableColumn } from 'primeng/table';

@Directive({
  selector: '[appAdDblClick]',
})
export class CellDblClickDirective implements OnInit {
  //#region Properties

  @Input('appAdDblClick')
  public editable = false;

  //#endregion

  //#region Constructor

  constructor(private editableColumn: EditableColumn) {}
  //#endregion

  //#region Events

  public ngOnInit(): void {
    if (this.editable) {
      this.editableColumn.onClick = (event: MouseEvent) => {
        const target = event.target as Element;
        if (
          this.editableColumn.dt.editingCell &&
          target &&
          this.editableColumn.dt.editingCell.contains(target)
        ) {
          this.editableColumn.dt.selfClick = true;
        }
      };
    }
  }

  @HostListener('dblclick', ['$event'])
  public onDblClick(event: MouseEvent) {
    if (this.editable && !this.editableColumn.dt.editingCell) {
      Reflect.apply(EditableColumn.prototype.onClick, this.editableColumn, [
        event,
      ]);

      this.editableColumn.dt.selfClick = false;
    }
  }

  //#endregion
}

jiangyh1024 avatar Mar 18 '22 07:03 jiangyh1024

It would also be nice to programmatically cancel the editing mode. Right now it doesn't seem possible to keep the a table row in edit mode while waiting for your API to return back a success or error for instance.

ssteezens avatar Jun 01 '22 17:06 ssteezens

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!

Best Regards,

mertsincan avatar Nov 09 '22 14:11 mertsincan