0

While using contextMenu (right-click) and table selection (left-click) both are maintaining two separate objects of row clicked. I want to perform the following task in PrimeNG- tree table, help me out:

  • Left-click select the first row.
  • Press Ctrl key and left-click select the second row.
  • Press Ctrl key and right-click select the third row and open context menu.

Expected result:

  • Maintain same select style for all the three rows.
  • Get an array of all the selected objects.

Actual result:

  • Maintains two different styles independently for left and right clicks.
  • It produces an array of objects for left-click selections and a separate independent object (not an array) for right click.

Right click is not allowing multiple selection.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102

1 Answers1

0

I was just wondering about the same issue and figured out a little work around.

There is a style class "ui-contextmenu-selected" which is added to the selected row with the right click. Using the event onContextMenuSelect you could remove that class from the row and select the row with the common way ( I assume that you have a variable 'selectedRow', so the only thing you have to do is to add the row data to your selectedRow var)

The tricky part here is just to filter and reach the HTML row from the selected context row data, using a little bit of JQuery won't be hard.

Edit: This is what I've done inside of the event trigger function

unselectContextRow( row ) {
this.selectedRow = row.data;
setTimeout(()=>{
    $('.ui-contextmenu-selected').removeClass('ui-contextmenu-selected');
})
}

This code works for single selection, if you want to make it work with multiple you just have to deal with the array.

Osakr
  • 1,027
  • 1
  • 13
  • 26
  • I prefer to manage the style and functionality via API so that the binding happens properly. – mohit lakhera Jul 04 '18 at 10:43
  • Of course, I prefer too but I haven't find a way doing properly with the PrimeNG API so I figured out this fix ( which is working perfect for me ). If you find a way to do it just lemme know pls ^^ – Osakr Jul 04 '18 at 11:09
  • Did you find another way to do it? – Osakr Jul 10 '18 at 15:11
  • there is way to achive it by using [contextMenuSelectionMode]="joint" – mohit lakhera Sep 10 '18 at 17:51
  • Fine, anyways I've been working with my workaround and no problems found, it is doing its job – Osakr Sep 11 '18 at 07:48
  • its good I was also working with a workaround, but recently I see this binding for table and same I implemented in tree-table and it worked – mohit lakhera Sep 17 '18 at 09:16