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

Customizable ContextMenu selection mode for Table and TreeTable #5558

Closed
ctrl-brk opened this issue Apr 13, 2018 · 9 comments
Closed

Customizable ContextMenu selection mode for Table and TreeTable #5558

ctrl-brk opened this issue Apr 13, 2018 · 9 comments
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@ctrl-brk
Copy link

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

[x] feature request

Current behavior
Currently left and right (when context menu is enabled) clicks maintain their own selection list, highlight items differently and so on. This is new functionality added to p-table in comparison with datatable.

Expected behavior
Add optional ability to make p-table selection like it was in old datatable, selecting items by both clicks and maintain a single selection list.

@cyberrranger
Copy link

you can use [(contextMenuSelection)]="selectedContext" and (onContextMenuSelect)="generateContext($event)" to add selectedContext to [(selection)]="selected"

@sivakumar55
Copy link

I am facing same issue
-> Context menu row selected style(right click) not clearing, after table row selection (left click)
Please suggest any solution.

image

@cyberrranger
Copy link

oh, same problem with selected item with my solution :/

@toregua
Copy link

toregua commented Jun 5, 2018

image
+1
Same problem for me

@toregua
Copy link

toregua commented Jun 5, 2018

I have found a solution just by playing with sass (css) like this for exemple :

body {
    .ui-table {
        .ui-table-tbody {
            &>tr {
                &:nth-child(odd) {
                    background-color: #f4f4f4;
                    &.ui-contextmenu-selected {
                        background-color: #f4f4f4;
                    }
                }
                &:nth-child(even) {
                    background-color: #fff;
                    &.ui-contextmenu-selected {
                        background-color: #fff;
                    }
                }
                &.ui-contextmenu-selected,
                &:nth-child(odd).ui-contextmenu-selected {
                    color: #000;
                    &.ui-state-highlight {
                        color: #fff;
                    }
                    .ui-panel,
                    .ui-table {
                        color: #000 !important;
                    }
                }
                &.ui-state-highlight,
                &:nth-child(odd).ui-state-highlight,
                &:nth-child(even).ui-state-highlight {
                    background-color: #89C487;
                    .ui-panel,
                    .ui-table {
                        color: #000 !important;
                    }
                }
            }
        }
    }
}

After that it works like the old p-DataTable

@ctrl-brk
Copy link
Author

ctrl-brk commented Jun 5, 2018

@toregua, This is just visual representation. Still you have to deal with two different lists/selections and unable to unselect context menu selection. I need it to be just like old datatable. One selection for everything. @cyberrranger solution is just a hack.

@toregua
Copy link

toregua commented Jun 6, 2018

@ctrl-brk you'are right, my solution look like old p-dataTable but needs to have [(selection)]="selected" and [(contextMenuSelection)]="selected" pointing on the same "selected" element.

@Chreggii
Copy link

Chreggii commented Jul 2, 2018

Try this:
@ViewChildren(ContextMenuRow) contextMenuRows: QueryList;

Unselect all context menu rows, when you select a row.
Use this to unselect all context menu rows:
this.contextMenuRows.forEach(r => r.selected = false)

@Merve7 Merve7 added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Jul 5, 2018
@Merve7 Merve7 added this to the 6.0.1 milestone Jul 5, 2018
@Merve7 Merve7 removed the Status: Pending Review Issue or pull request is being reviewed by Core Team label Jul 6, 2018
@cagataycivici cagataycivici changed the title p-table - add item selection when context menu opens Customizable ContextMenu selection mode Jul 9, 2018
@cagataycivici cagataycivici self-assigned this Jul 9, 2018
@cagataycivici cagataycivici added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label Jul 9, 2018
@cagataycivici
Copy link
Member

New contextMenuSelectionMode="separate|joint" allows customization of this behavior. An example with "joint" where row selection and context menu uses the same selection property.

<p-table [columns]="cols" [value]="cars" selectionMode="single" [(selection)]="selectedCar" [contextMenu]="cm" contextMenuSelectionMode="joint">
    <ng-template pTemplate="header" let-columns>
        <tr>
            <th *ngFor="let col of columns">
                {{col.header}}
            </th>
        </tr>
    </ng-template>
    <ng-template pTemplate="body" let-rowData let-columns="columns">
        <tr [pSelectableRow]="rowData" [pContextMenuRow]="rowData">
            <td *ngFor="let col of columns">
                {{rowData[col.field]}}
            </td>
        </tr>
    </ng-template>
</p-table>

<p-contextMenu #cm [model]="items"></p-contextMenu>

@cagataycivici cagataycivici changed the title Customizable ContextMenu selection mode Customizable ContextMenu selection mode for Table and TreeTable Jul 11, 2018
cagataycivici pushed a commit that referenced this issue Jul 11, 2018
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

No branches or pull requests

7 participants