Using Data Virtualization
As the case of handling a lot of data is quite common, the requirement for fast data processing becomes more and more indispensable. The result of this necessity is the Data Virtualization technique that ensures much better performance as well as user experience improvements.
The virtual collection is designed for ReadOnly purposes only and it is not recommended to be used in other scenarios when updates are required. Add/insert scenario is not supported with VirtualQueryableCollectionView as it cannot maintain cache of the already loaded items.
When working with the UI components that enable UI virtualization, you may take advantage of the above mentioned technique by using VirtualQueryableCollectionView class. It enables you to benefit from the on-demand data loading to smooth scrolling with UI virtual components. VirtualQueryableCollectionView provides you with the following important members:
LoadSize property: defines the maximum number of items requested at once;
VirtualItemCount property: defines the total number of items available on the server-side;
ItemsLoading event : will be raised when the collection is requesting item at some index and this item is not already loaded. The arguments in this event are as follows:
StartIndex : requested item index;
ItemCount : number of requested items (can be less than or equal to the LoadSize).
When using VirtualQueryableCollectionView for WPF, you may easily benefit from the built-in sorting, grouping, filtering, etc. functionality if you provide IQueryable as a source and just set LoadSize property to desired value. For example:
Example 1: Wrap a query in a VirtualQueryableCollectionView
var context = new NorthwindEntities();
var query = context.Order_Details.OrderBy(o => o.OrderID);
var view = new VirtualQueryableCollectionView(query) { LoadSize = 10 };
DataContext = view;
Dim context = New NorthwindEntities()
Dim query = context.Order_Details.OrderBy(Function(o) o.OrderID)
Dim view = New VirtualQueryableCollectionView(query) With {.LoadSize = 10}
DataContext = view
In the example above Entity Framework is used. However, you may use Linq to SQL, OpenAccess or any other Linq provider in the same manner.
When ScrollMode is configured as Deferred, then a ScrollPositionIndicator will be shown as the user scrolls vertically. Its content will be an empty value until the user releases the scrollbar to a particular position so that the items to be displayed into view are actually loaded. In order to avoid this, you could permanently hide the indicator by setting the ShowScrollPositionIndicator property of the RadGridView to False. This property is available since the 2018.3.1029 version.
Example 2: Binding RadGridView
<telerik:RadGridView ItemsSource="{Binding}" />
Filtering is only supported with IQueryable data sources.
Filtering on Distinct Values is not fully supported when using the VirtualQueryableCollectionView. We suggest configuring GridViewDataColumn with ShowDistinctFilters="False". That way only filtering through the Field Filters will be enabled. You can check the basic filtering section as a reference on the filtering support. There you can also find more information on how to filter through the Field Filters.
ItemsLoading event
ItemsLoading event will be raised if you try to access some item by index and this item is not yet loaded. When you scroll down, the ItemsLoading event will be called and the empty(null) items in the collection will be replaced with the new items. When an item is already loaded the collection will not call ItemsLoading event for this item.
When you provide IQueryable in the VirtualQueryableCollectionView you do not need to handle the ItemsLoading event.
Check out the DataVirtualization demos in our WPF Demos application.
You can also check this blog.