This is a migrated thread and some comments may be shown as answers.

React Grid Selection Clear / Repositioning

2 Answers 385 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 15 Feb 2019, 08:54 PM

In a current scenario we were working through where we have a groupable / sortable grid that allows inline editing, we wanted to be able to keep the currently selected row in focus even after the user might have changed a value that effects the groupable / sortable criteria, thus causing a re-positioning of the row.  The current documented examples provided an option for looping through the data to set/unset a selection tag, but this seems problematic with the way grouping changes the data into a hierarchical structure (we do not force a grouping so sometimes the data will be flat). 

Two things would have helped our situation since we are only allowing one row to be selected at a time:  either a setting on the grid that only allowed for single row selections (and so thus we wouldn't have to loop the data to un-set the flag for all rows manually), or a clearSelection method that would automatically clear the flag for all rows.  In both of those examples we would only have to deal with setting the current row's selection flag.  In addition, both of those types of functionality are available with other Kendo technologies (e.g. jQuery)

 

Did I overthink this issue and there is actually a better way of solving this issue?

2 Answers, 1 is accepted

Sort by
0
James
Top achievements
Rank 1
answered on 15 Feb 2019, 08:58 PM
Another option that might have worked was to have a reference in the rowClick event (or update event) to all the rows currently selected so that we could set those flags directly without looping through all the data. 
0
Stefan
Telerik team
answered on 18 Feb 2019, 07:15 AM
Hello, James,

Thank you for the details and suggestions.

The specific part here is that the selection(and many other features) depend on the data, the Grid itself will not internally modify it to follow the React principals for immutable data. This is the reason why we are not preventing more than one row to be selected or internally cleating the selection as in the jQuery version.

In general, removing the other selected row should not cause an additional loop. As one loop is needed to set the current record as selected, all other records can be set the not selected within if else statement. When editing the data, the same row should remain as selected as this is connected to the data item.

I can suggest using the scrollIntoView method on the selected element.

Similar to this example:

https://stackblitz.com/edit/react-ccjrvg?file=app/main.js
 
Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
James
Top achievements
Rank 1
Answers by
James
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or