Primeng: DataTable Single Mode Selection doesn't unselect

Created on 25 Aug 2016  路  8Comments  路  Source: primefaces/primeng

From [http://www.primefaces.org/primeng/#/datatableselection]: "In single mode, a row is selected on click event of a row. If the row is already selected then the row gets unselected."

Instead, clicking on a selected row simply fires another onRowSelect event. This behavior can be seen in the Showcase example at the link above.

defect

Most helpful comment

You need to add [metaKeySelection]="false" property to the dataTable and then it should work. It also states that in the documentation under the section 'multiple'

All 8 comments

Hi Guys,

I am still facing same issue in 1.0.0-rc.5. In my scenario, the selection mode is single and I have only one data item in table. Even same is not working in live examples on site.

http://www.primefaces.org/primeng/#/datatable/selection

Can you please test on it and revert. On selecting again, it still fires onRowSelect event.

Thanks,
Nabeel

A workaround for same is to press Ctrl while selecting again and it will allow to deselect.

still am facing same issue onRowUnselect. its not firing. using 1.0.0-beta.17

issue still exists with 1.1.0, can be observed on http://www.primefaces.org/primeng/#/datatable/selection. no unselect events are fired for mouse clicks, seems to work for touch though (tested with chrome devtools device emulation).

You need to add [metaKeySelection]="false" property to the dataTable and then it should work. It also states that in the documentation under the section 'multiple'

I have the same issue as mentioned above.
My table is working normally,
<p-dataTable selectionMode="single" [(selection)]="selectedUser" (onRowSelect)="onRowSelect($event)" (onRowUnselect)="onRowUnselect($event)" [value]="users" expandableRows="true" [editable]="true" [rowsPerPageOptions]= [5,10] [rows]="5" paginator="true">
It just does not unselect. So when I add the [metaKeySelection]="false" it unselects the row, BUT now I get a weird error on the console.

On selecting a row the first error that pops is TypeError: Cannot read property 'id' of undefined
Unselecting the row works fine.
Selecting the same row again the error now reads TypeError: Cannot read property 'id' of null

Any idea whats going wrong?

@mugrufis thank you for the [metaKeySelection]="false", it helped me. I didn't have your TypeError problem though. One thing I have different from you is, that I don't use selection in a two way data binding, I only set the value.

But I wrap p-datatable in my own datatable component and heavily extend it, so I don't think I can help you:/ I just wanted to say thank you.

Edit: I just noticed that @MakhouT was the first one who gave the advice. So thank to you too :)

I created a method to deselect a row programmatically after selecting a single row and it works fine.

@ViewChild(Table, { static: true }) public table: Table; private unSelectRows(): void { this.table._selection = null; this.table.selectionKeys = {}; this.table.selectionChange.emit(null); }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pchristou picture pchristou  路  3Comments

garethlewis picture garethlewis  路  3Comments

philly-vanilly picture philly-vanilly  路  3Comments

lilling picture lilling  路  3Comments

gatapia picture gatapia  路  3Comments