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

Virtual Scrolling with DTOs

2 Answers 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jwize
Top achievements
Rank 1
jwize asked on 06 Feb 2014, 07:53 AM
Existing Service Layer With DTOs
How do I get my existing dataservice layer, which returns DTOs, to support virtual scrolling? I can pass the DataSourceRequest object to the service layer where the DTOs are created but I can't seem to translate the request object into any useful queries.

Manual Filtering Seems Clunky
I can manually implement some of the filtering by using switch statements but this has a horrible amount of overhead.

Dynamic Expression Trees
I was thinking maybe I could create something that parses the FilterDescriptors and creates LINQ Expression Trees to apply to the IQueryable somehow but this also seems to be a little complex for my liking. I like this idea because I can see the power of learning how this API works but I don't have the time to author this at the moment. I also don't know if this will be feasible for performance. 

Where are all the code examples?
I haven't seen any examples that help me tackle this problem. 

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 10 Feb 2014, 12:18 PM
Hi Jaime,

Telerik UI for ASP.NET MVC includes the ToDataSourceResult extension method which automatically applies the DataSourceRequest over an existing IEnumerable or IQueryable. You can find more info in the ajax binding help topic.

On a side note the virtual scrolling only requires paging to be applied. This is very easy to implement using the Take and Skip built-in extension methods of the IQueryable/IEnumerable. If virtual scrolling is the only thing required you don't need to use the ToDataSourceResult extension method.

Finally you can check the ASP.NET MVC sample application which ships with the installation.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
jwize
Top achievements
Rank 1
answered on 10 Feb 2014, 07:39 PM
Yeah, I figured it out. This should really be in the remote  data example. 

Using Automapper (with my types)
Mapper.CreateMap<Employee, HomeEmployeeView>();
return employees.ToDataSourceResult(request, Mapper.Map<HomeEmployeeView>);

Telerik Example (northwind db)
IQueryable<Product> products = northwind.Products;
// Convert the Product entities to ProductViewModel instances
DataSourceResult result = products.ToDataSourceResult(request, product => new ProductViewModel
{
ProductID = product.ProductID,
ProductName = product.ProductName,
UnitsInStock = product.UnitsInStock
});
return Json(result);
Tags
Grid
Asked by
jwize
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
jwize
Top achievements
Rank 1
Share this question
or