This question is locked. New answers and comments are not allowed.
frederic rybkowski
Top achievements
Rank 1
frederic rybkowski
asked on 08 Mar 2011, 05:40 PM
Hi,
Great WorkTelerik Team !
GridDataProcessor class does not deal with GridCommand.
It fetches all info and filters (sort, group, filter, page size, current page) in the Controller Context.
Could we think of something like GridDataCommandProcessor that will use GridCommand (for custom binding).
Here is the way I found to use AutoMapper and CustomBinding:[GridAction(EnableCustomBinding = true)]public virtual ActionResult _getBids(GridCommand command){ int count = 0; // in a bootstrapper : Mapper.CreateMap<Record_DB, Record_DTO>(); var context = new DatabaseEntities(); // EF var data = context.Record_DBs; var data_Db = GetData<Record_DB>(context.Record_DBs, "KEY1,KEY2", command, out count); var data_Dto = Mapper.Map<IEnumerable<Record_DB>, List<Record_DTO>>(data_Db); return View(new GridModel { Data = data_Dto, Total = count });}private static IEnumerable<T> GetData<T>(IQueryable dataSource, string dataKeys, GridCommand command, out int count) where T: class{ var model = new GridModel(dataSource); var dataProcessor = new GridDataCommandProcessor( command, new GridActionBindingContext(false, null, model.Data, model.Total) ); // For SqlServer2000... var keys = dataKeys.Split(new Char[] { ',' }); foreach (string key in keys) { if (key.Trim() != "") { dataProcessor.SortDescriptors.Add( new SortDescriptor { Member = key.Trim(), SortDirection = System.ComponentModel.ListSortDirection.Ascending } ); } } count = dataProcessor.Total; return dataProcessor.ProcessedDataSource.Cast<T>();}8 Answers, 1 is accepted
0
frederic rybkowski
Top achievements
Rank 1
answered on 09 Mar 2011, 10:18 AM
Could you add the following class to the project ?
And the static function GetData... ?
This will allow us to have the IQueryable result based on GridCommand information only.
And the static function GetData... ?
This will allow us to have the IQueryable result based on GridCommand information only.
public static IEnumerable<T> GetData<T>(IQueryable dataSource, GridCommand command, out int count) where T: class { var model = new GridModel(dataSource); var dataProcessor = new GridDataCommandProcessor( command, new GridActionBindingContext(false, null, model.Data, model.Total) ); count = dataProcessor.Total; return dataProcessor.ProcessedDataSource.Cast<T>(); }namespace Telerik.Web.Mvc.UI{ using System.Collections; using System.Collections.Generic; using System.Linq; using Extensions; using Infrastructure; using Telerik.Web.Mvc.UI; public class GridDataCommandProcessor { private readonly IGridBindingContext bindingContext; private readonly GridCommand command; private bool dataSourceIsProcessed; private int totalCount; private IEnumerable processedDataSource; private IList<SortDescriptor> sortDescriptors; private IList<IFilterDescriptor> filterDescriptors; private IList<GroupDescriptor> groupDescriptors; public GridDataCommandProcessor(GridCommand command, IGridBindingContext bindingContext) { Guard.IsNotNull(bindingContext, "bindingContext"); this.bindingContext = bindingContext; this.command = command; } public int Total { get { EnsureDataSourceIsProcessed(); return totalCount; } } public IList<SortDescriptor> SortDescriptors { get { if (sortDescriptors == null) { sortDescriptors = command.SortDescriptors; if (sortDescriptors == null) { sortDescriptors = bindingContext.SortDescriptors; } } return sortDescriptors; } } public virtual IList<GroupDescriptor> GroupDescriptors { get { if (groupDescriptors == null) { groupDescriptors = command.GroupDescriptors; if (groupDescriptors == null) { groupDescriptors = bindingContext.GroupDescriptors; } } return groupDescriptors; } } public IList<IFilterDescriptor> FilterDescriptors { get { if (filterDescriptors == null) { filterDescriptors = command.FilterDescriptors; if (filterDescriptors == null) { filterDescriptors = bindingContext.FilterDescriptors.Cast<IFilterDescriptor>().ToList(); } } return filterDescriptors; } } public int PageCount { get { EnsureDataSourceIsProcessed(); int pageSize = command.PageSize; if ((totalCount == 0) || (pageSize == 0)) { return 1; } return (totalCount + pageSize - 1)/pageSize; } } public IEnumerable ProcessedDataSource { get { EnsureDataSourceIsProcessed(); return processedDataSource; } } public int CurrentPage { get { return command.Page; } } private void EnsureDataSourceIsProcessed() { if (dataSourceIsProcessed) { return; } if (bindingContext.DataSource == null) { dataSourceIsProcessed = true; return; } if (!bindingContext.EnableCustomBinding) { GridModel model; var dataTableEnumerable = bindingContext.DataSource as GridDataTableWrapper; if (dataTableEnumerable != null) { model = dataTableEnumerable.ToGridModel(CurrentPage, command.PageSize, SortDescriptors, FilterDescriptors, GroupDescriptors); } else { IQueryable dataSource = bindingContext.DataSource.AsQueryable(); model = dataSource.ToGridModel(CurrentPage, command.PageSize, SortDescriptors, FilterDescriptors, GroupDescriptors); } totalCount = model.Total; processedDataSource = model.Data.AsGenericEnumerable(); } else { processedDataSource = GetCustomDataSource(bindingContext.DataSource); totalCount = bindingContext.Total; } dataSourceIsProcessed = true; } private IEnumerable GetCustomDataSource(IEnumerable dataSource) { var customDataSourceWrapper = dataSource as IGridCustomGroupingWrapper; if (customDataSourceWrapper != null) { return customDataSourceWrapper.GroupedEnumerable.AsGenericEnumerable().AsQueryable(); } return dataSource; } }}0
Alexandre Jobin
Top achievements
Rank 1
answered on 09 Mar 2011, 05:52 PM
hi frederic!
what you suggest is defenitely what i need. Here's my post about the subject: how to use CustomBinding with ViewModel
but just one thing. Have you tried to group a colomn? i tried that on my side and it doesnt work. Maybe im doing something wrong. Heres the error message that i get:
hope your suggestion will go in the telerik code!!
alex
what you suggest is defenitely what i need. Here's my post about the subject: how to use CustomBinding with ViewModel
but just one thing. Have you tried to group a colomn? i tried that on my side and it doesnt work. Maybe im doing something wrong. Heres the error message that i get:
Unable to cast object of type 'Telerik.Web.Mvc.Infrastructure.AggregateFunctionsGroup'to type 'MTO.GIPI.Domain.PublicationIntervenant'.
hope your suggestion will go in the telerik code!!
alex
0
frederic rybkowski
Top achievements
Rank 1
answered on 09 Mar 2011, 11:02 PM
Salut Alexandre,
I use the above solution and it works,
Insert the file with
in the Telerik assembly next to
then rebuild.
I use it with sorting filtering,,, but didn't try the grouping at this time, will try tomorrow.
GridDataProcessor using GridCommand is really missing.
Hope Telerik team reads us !
Bonsoir.
I use the above solution and it works,
Insert the file with
GridDataCommandProcessor in the Telerik assembly next to
GridDataProcessor then rebuild.
I use it with sorting filtering,,, but didn't try the grouping at this time, will try tomorrow.
GridDataProcessor using GridCommand is really missing.
Hope Telerik team reads us !
Bonsoir.
0
Alexandre Jobin
Top achievements
Rank 1
answered on 09 Mar 2011, 11:32 PM
Salut Frederic!
this is what i did. I've added your code to the Telerik assembly and used the new dll.
hope you will find a way to use the grouping feature!
bonne journée!
alex
this is what i did. I've added your code to the Telerik assembly and used the new dll.
hope you will find a way to use the grouping feature!
bonne journée!
alex
0
Alexandre Jobin
Top achievements
Rank 1
answered on 14 Mar 2011, 04:01 PM
hi frederic,
do you have any news for grouping feature to work with your code?
alex
do you have any news for grouping feature to work with your code?
alex
0
frederic rybkowski
Top achievements
Rank 1
answered on 14 Mar 2011, 05:48 PM
I known there is a big problem when grouping...
I can't spend time on this point... as i don't offer grouping in my grids...
Désolé.
Where can we ask for enhancements in order to have GridCommand Data Processor in next release ?
I can't spend time on this point... as i don't offer grouping in my grids...
Désolé.
Where can we ask for enhancements in order to have GridCommand Data Processor in next release ?
0
Alexandre Jobin
Top achievements
Rank 1
answered on 18 Mar 2011, 02:32 PM
hi frederik,
i've found a way to make everything work for us. Look at my other post for a solution: here
give me some feedback if you can!
alex
i've found a way to make everything work for us. Look at my other post for a solution: here
give me some feedback if you can!
alex
0
Luis
Top achievements
Rank 1
answered on 07 Jan 2012, 03:13 PM
Finally I got it!
With the help of the guys on this thread I'm proud to say that I came to a satisfactory result, pluggable in any type of MVC application without much difficulty and almost none in the settings.
I published the project on Bitbucket and Nuget, please take a look and send me some feedbacks.
https://bitbucket.org/Lunadie/telerikmvcgridcustombindinghelper/wiki/Home
https://nuget.org/packages/TelerikMvcGridCustomBindingHelper
With the help of the guys on this thread I'm proud to say that I came to a satisfactory result, pluggable in any type of MVC application without much difficulty and almost none in the settings.
I published the project on Bitbucket and Nuget, please take a look and send me some feedbacks.
https://bitbucket.org/Lunadie/telerikmvcgridcustombindinghelper/wiki/Home
https://nuget.org/packages/TelerikMvcGridCustomBindingHelper