question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to deselect row in single select mode

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[ x ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior Once a row is selected, it can’t be deselected by using ctrl + click as with multi select.

Expected behavior User can select a single row and deselect it.

Reproduction of the problem http://swimlane.github.io/ngx-datatable/#single-selection

What is the motivation / use case for changing the behavior? I’d like a user to be able to clear their selection without having to provide an extra button. I have a ui where the user will load the grid per a selection in a drop down. To proceed, they will either select a child item in the grid or just keep their option from the drop down. If the user selects something from the grid but changes their mind, they have to reset their selection by changing their selection in the drop down. Yes, this is a fairly specific use case, however the ability to deselect a single row seems reasonable and in line with the other selection modes.

  • Table version: 7.0.0
  • Angular version: 4.1.3
  • Browser: [all ]

  • Language: [TypeScript 2.3.2]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
dalelottscommented, Oct 17, 2018

Actually, this feature is easy to implement yourself.

Add this to the data table

[selectCheck]="singleSelectCheck"

Then define the function in your class.

  singleSelectCheck (row:any) {
     return this.selected.indexOf(row) === -1;
  }

One thing to know about the selectCheck implementation is that at runtime the this context is bound to the DataTableSelectionComponent class instance. There are two ways to deal with this:

  1. No matter what your local selected array is named, reference this.selected, which may confuse the typescript compiler. (I didn’t try to find a way for the compiler to accept this if the local variable has a different name)
  2. (preferred) bind the selectCheck function to your component instance by adding this.singleSelectCheck = this.singleSelectCheck.bind(this); to the constructor.

The following definition of singleSelectCheck will eliminate the need to bind the function in the constructor:

  singleSelectCheck = (row:any) => {
     return this.selected.indexOf(row) === -1;
  }
2reactions
amcdnlcommented, Aug 4, 2017

@dalelotts - Thanks for providing that solution! Would you mind PR’n this to the docs for others?

Read more comments on GitHub >

github_iconTop Results From Across the Web

DataGrid - How to deselect an already selected row in single ...
Hello, I want to un-select already selected row in the single selection mode. Is there any ways to do it in React?
Read more >
how to prevent deselect in full-row single-select mode - MSDN
To Prevent The Deselection of Rows in a Datagridview Control while pressing the CTRL Key from Keyboard and Clicking the mouse i.e[CTRL+Click]..
Read more >
Deselect selected rows from ag grid angular - Stack Overflow
To programatically deselect a single row, use rowNode.setSelected(false) . rowNode.setSelected(isSelected, clearSelection) can be used to select ...
Read more >
UnSelect in single mode in UI for WPF | Telerik Forums
Here is what I want to happen. 1. I only want one row to be selected at a time. Any other rows to...
Read more >
Workaround for missing "Clear selection" on single-select tables
While the Retool team works to restore the ability to deselect a row in a single-select-mode table (hint, hint) you can reasonably replicate ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found