Ticket T1017812
Visible to All Users

DataGrid - How to deselect an already selected row in single selection mode

created 4 years ago

Hello,

I want to un-select already selected row in the single selection mode. Is there any ways to do it in React?

Below is the sample project I created:
https://codesandbox.io/s/row-selection-devextreme-data-grid-forked-nkbx8?file=/App.js

Screen Shot 2021-07-28 at 5.42.09 PM.png

Thank you!

Answers approved by DevExpress Support

created 4 years ago

Hello,

We recommend using the onCellClick event for this task. It allows you to check if the clicked row is already selected via the e.row.isSelected parameter. You can call the DataGrid's clearSelection() method to remove the selection.

JavaScript
onCellClick(e) { if (e.row.isSelected) { e.component.clearSelection(); } }

I created a snippet to demonstrate the approach. This will clear the selection if a row is already selected.

I checked records in our database, and it seems that you started using DevExtreme recently. I collected help topics, demos, and other resources that will help you find solutions for common scenarios quickly and develop with DevExtreme more effectively:

  • React Demos. They illustrate component configurations in the most common scenarios;
  • API Reference. This topic contains detailed information on each of our properties and methods;
  • Widgets. This section lists help topics that describe the concept of DevExtreme components;
  • DevExtreme React Components. This help section describes specifics of our React components;
  • Support Center tickets. There, you can find answers and ready-to-use solutions for typical inquiries;
  • Knowledge Base articles. Such articles are user guides or describe how to solve common issues;
  • Examples of how to implement common scenarios.

If you experience issues with our components, it is better to create a simple project demonstrating these issues and attach it to your ticket (see A request for simple example programs). With a small example project, it is much easier for us to verify that your code that calls ours is valid and our components are used as recommended. This way, we will be able to focus on the problematic area. You can use our React template to create such demo projects.

Let us know if you have further questions.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.