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

Faster way to select rows on the grid?

5 Answers 186 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 2
Iron
Veteran
Iron
Richard asked on 09 Sep 2020, 08:08 PM

Hi,

I'm using  grid.SelectedItems.Add(row); in a loop to select rows on a grid. However sometimes I need to select 10,000+ rows and this can take over 15 seconds. I have tired .AddRange() but that takes the same amount of time. 

Is there a faster way to select items, especially with a very large number of rows?

Thanks,

Richard

5 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 10 Sep 2020, 09:04 AM

Hi Richard,

To enable fast programmatic selection of a range of items, you can use the SelectItemsRange method of the RadGridView control.

Can you please give it a try and let me know if it works for you?

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Richard
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 10 Sep 2020, 09:19 AM

Hi Dilyan,

I had a look at that option but unfortunately it doesn't fit my use case. A user can select rows on the grid by pasting in a list of Ids from an external source, e.g. Excel. That means I can't give a start / end index as selected rows are scattered all over the grid.  

For 1,000 Ids this takes a less than a second but for 10,000 it takes 15+ seconds and the UI feels like it has crashed. 

If it can't be done it's ok, I can instead send the Ids to the server as a SQL filter rather than a grid selection but it would be a better user experience if I could select them.

 

Example code below where idHash is a HastSet<int> of 10,000 Ids.

 

Thanks,

Richard

 
// Pause Grid SelectionChanged Event
_grid.SelectionChanged -= GridOnSelectionChanged;
 
 
var lastIdToSelect = idHash.First();
idHash.Remove(lastIdToSelect);
 
 
// Select the rows on the grid
foreach (IId row in _grid.Items)
    if (idHash.Contains(row.Id))
        _grid.SelectedItems.Add(row);
 
 
// Resume Grid SelectionChanged Event
_grid.SelectionChanged += GridOnSelectionChanged;
 
// Select 1 last row to trigger selection event
foreach (IId row in _grid.Items)
{
    if (row.Id != lastIdToSelect) continue;
    _grid.SelectedItems.Add(row);
    break;
}
0
Accepted
Dilyan Traykov
Telerik team
answered on 14 Sep 2020, 02:15 PM

Hi Richard,

Thank you for the clarification and the provided code snippet.

In this case, I believe you can use the control's Select method to select the required items:

            var lastIdToSelect = idHash.First();
            idHash.Remove(lastIdToSelect);

            var selection = new List<IId>();
            // Select the rows on the grid
            foreach (IId row in _grid.Items)
                if (idHash.Contains(row.Id))
                    selection.Add(row);

            _grid.Select(selection);
Please note that for the method to work as expected, the SelectionMode of the control needs to be set to either Mixed or Extended.

I've noticed that this method is not present in our Programmatic Selection article and will update it as soon as possible.

In the meantime, please let me know if the Select method does indeed work for you.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Richard
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 14 Sep 2020, 05:00 PM
That's works great , thank you Dilyan
0
Dilyan Traykov
Telerik team
answered on 15 Sep 2020, 11:06 AM

Hi Richard,

I'm happy to hear that the Select method works for you. I wish to note that I've already documented the method in our documentation and it will soon be accessible.

As always, feel free to contact me again should you require further assistance.

Regards,
Dilyan Traykov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
GridView
Asked by
Richard
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Dilyan Traykov
Telerik team
Richard
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or