[Data Grid Reactive] Deselecting a column or cell
Forge component by Bruno Martinho
Application Type
Reactive

When a user clicks on a cell or column, then does a new search, which refreshes data, the first cell in the column that was clicked remains highlighted. How can we clear the selection?

Solution

Hello @Joseph Marlin ,

We've created a sample that should help you achieving your use case.

It requires to extend the component writing some JS, that should be in the Ready event of the page containing the Data Grid.

It will allow to set the selection, after data is bound to the grid. In the example we set the selection to the first cell (first row and first column).

The JS code to this is the following:

If you don't any selection at all, you can set to (-1, -1) instead of (0,0), although this might have some side effects, in some edge cases, in features like copy and export.  

We have in attachment an OML with a sample for you to check.

Please bear in mind that we didn't make all the necessary tests to ensure that it will work on all cases. 

Let us know if this helps.

Thanks,

Bruno Martinho

DataGridReactiveChangeSelection.oml

Hello @Joseph Marlin ,

In order to help, can you give some more details on what you are trying to accomplish, please?

Having no selection in the grid might have some side effects, in some edge cases, in features like copy and export.

Also, you have mentioned doing a search, is this search in server side or inside the grid data?

Please let us know, so we can understand better the case.

Thanks,

Bruno Martinho


The issue is that there can be no selection, because this is a new set of data, after the user does a new search of the database with new criteria, and a new dataset is returned. The grid "remembers" that the user had previously clicked on a cell in column x, on row y, which caused that cell to be highlighted. After the grid is refreshed with the new data, it now selected row 1 on column x, even though this is an entirely new set of data. Makes no sense.

Solution

Hello @Joseph Marlin ,

We've created a sample that should help you achieving your use case.

It requires to extend the component writing some JS, that should be in the Ready event of the page containing the Data Grid.

It will allow to set the selection, after data is bound to the grid. In the example we set the selection to the first cell (first row and first column).

The JS code to this is the following:

If you don't any selection at all, you can set to (-1, -1) instead of (0,0), although this might have some side effects, in some edge cases, in features like copy and export.  

We have in attachment an OML with a sample for you to check.

Please bear in mind that we didn't make all the necessary tests to ensure that it will work on all cases. 

Let us know if this helps.

Thanks,

Bruno Martinho

DataGridReactiveChangeSelection.oml

Thank you for the quick response! We'll give it a try.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.