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

Telerik Grid MVC using a Dynamic DataTable with Ajax Binding

16 Answers 426 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ramesh
Top achievements
Rank 1
Ramesh asked on 26 Aug 2011, 12:22 PM
Hi,

I am using Telerik MVC Grid version 2011.2.712.340.

We have a requirement to bind a Dynamic Data or Data Table to Telerik Grid in MVC using Ajax Binding. I have found a nice post by Alex Rogan in the below URL 
http://alexrogan.com/?p=13

By following the above approach I am able to bind the Grid but I am not able to work with any of the Grid features like Sorting, Grouping, Filtering. Please find the code for this in the attachment.
 
Let me know if you need more information. Please help.

Thanks
Ramesh M
 

16 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 26 Aug 2011, 03:22 PM
Hi Ramesh, 

We are not familiar with the implementation from that blog post. That's why I would suggest you check the following code libraries for running implementations:

  1. Binding to dynamic objects
  2. Binding to DataTable

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Ramesh
Top achievements
Rank 1
answered on 29 Aug 2011, 10:19 AM
Hi,

Thank you for this information.

I have used the code in item #2 below. This approach solved my requirement to some extent. We need to implement custom binding using the datatable by setting the EnableCustomBinding to true. When I do this in the example given below, the Sorting, Filtering and Grouping features doen not work at all. Do I need to do something different. 

Thanks
Ramesh M 
0
Atanas Korchev
Telerik team
answered on 29 Aug 2011, 12:16 PM
Hello Ramesh,

 When you enable custom binding you should implement paging, sorting, filtering and grouping. Did you implement those in your code? 

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Ramesh
Top achievements
Rank 1
answered on 29 Aug 2011, 12:27 PM
Atanas,
 
Yes I have implemented but it did not work for me. I am using client side binding to populate the grid data and when I return the data in the form of datatable I am getting a script error. Since the datatable cannot be serialized (cannot convert to json) I am getting a script error.

Is there any work around for this issue.

Thanks
Ramesh M      
0
Atanas Korchev
Telerik team
answered on 29 Aug 2011, 12:48 PM
Hello Ramesh,

The code library which I linked before is also using ajax binding to datatable. Please make sure you are using the same code when returning the data from your action method which binds the grid:

[GridAction]
public ActionResult Select()
{
     return View(new GridModel(GetDataTable());
}

If you still cannot get it to work I would ask you to send a sample project which demonstrates your current implementation. 

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Ramesh
Top achievements
Rank 1
answered on 29 Aug 2011, 01:00 PM
Atanas,

In the code sample you sent by you is using ajax binding to datatable but custom binding is not enabled. So when I use the custom binding and return the datatable I am getting the scrtipt error. When I use the custume binding telerik grid is expecting IEnumarable data instead of a datatable.

One more thing I have noticed is when I bind the datatable to the telerik grid I am unable to see any filter conditions which are shown in the popup screen when i Click on column filter icon.    

Let me know if this data helps or I will send the code I am working on.

Thanks 
Ramesh M

  
0
Atanas Korchev
Telerik team
answered on 29 Aug 2011, 01:17 PM
Hello Ramesh,

 You need to set the type of the column in order to enable the filtering.

 Please do send me a sample project showing your custom binding.

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Ramesh
Top achievements
Rank 1
answered on 29 Aug 2011, 01:47 PM
Atanas,

Attached is the sample project showing the custom binding. In this sample I am using List<Dictionary<string, object>> collection to bind the grid. I am using the BindingHelper class provided in Telerik Grid samples which accepts input of type 

IQueryable.

 

 

So I am converting by data in this format. This works for me except filters.

Please look into this code and suggest if this is the right approach to do this.
 
Thanks 
Ramesh M        

0
Atanas Korchev
Telerik team
answered on 30 Aug 2011, 07:33 AM
Hi Ramesh,

 The ExpressionBulider does currently work with dictionaries. That's why you need to implement the filtering using LINQ extension methods. Find attached the updated project.

Kind regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Ramesh
Top achievements
Rank 1
answered on 30 Aug 2011, 12:51 PM
Atanas,

Thank you for the updated project. This worked fine when I bind the columns using datarow collection. When I use the GridColumnSettings collection I am unable to get the grid column filters. On furthur investigation, I found that when we bind the columns using GridColumnSettings we are no where setting the column datatype, due to this I think the filters are not showing.

I have attached the sample project which explains my scenario. 

Thanks
Ramesh M 

     

 

 


0
Atanas Korchev
Telerik team
answered on 31 Aug 2011, 09:55 AM
Hi Ramesh,

 Indeed you cannot set the MemberType from  GridColumnSettings. The good news is that we have recently implemented this feature and it will be included in the next official release which is due in the middle of next month. Till then you can define your columns in the View as a workaround.

All the best,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Ramesh
Top achievements
Rank 1
answered on 05 Sep 2011, 07:43 AM
Atanas,

Thank you for this information. We need to use GridColumnSettings for column binding because this provides more options. We will wait for the next release with the Filters as an open item.

Thanks
Ramesh M  

0
Ramesh
Top achievements
Rank 1
answered on 06 Sep 2011, 08:38 AM
Atanas,

Finally we are able to bind the datatable to the telerik grid with all the features. While verifing this we got an issue with grouping the columns. The grouping works when we drag a single column to the grouping section. When we group on multiple columns, the data is grouped with the column dropped at the first time. Please find the attached screenshot for how this looks when I group on multiple columns. Also I have attached the sample project I am working on.

Thanks in advance for you help.

Thanks
Ramesh M    
0
Atanas Korchev
Telerik team
answered on 06 Sep 2011, 08:55 AM
Hello Ramesh,

You have implemented custom binding and probably it does not handle nested grouping properly. If you disable the custom binding grouping will work as expected. I am sending a modified version showing how to use use that. 

 If you must use custom binding you can check your grouping code for any problems. 

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
ROB
Top achievements
Rank 1
answered on 24 Oct 2011, 12:12 AM
If you replace the ApplyGrouping method with the one below then it will work. It was because of the group variable scope was being re-referenced and the inner lambda was still accessing the previous. Access to modified closure was being displayed in resharper:

public static IEnumerable ApplyGrouping(this IQueryable<Dictionary<string, Object>> data, IList<GroupDescriptor> groupDescriptors)
{
    Func<IEnumerable<Dictionary<string, Object>>, IEnumerable<AggregateFunctionsGroup>> selector = null;
    foreach (var group in groupDescriptors.Reverse())
    {
        GroupDescriptor g1 = group;
        if (selector == null)
        {
            selector = orders => BuildInnerGroup(orders, o => o[g1.Member]);
        }
        else
        {
            selector = BuildGroup(o => o[g1.Member], selector);
        }
    }
 
    if (selector == null)
        return data;
 
    return selector.Invoke(data);
}
0
Stefan Vantchev
Top achievements
Rank 1
answered on 15 Jan 2013, 06:48 PM
Hi, 
I don't understand how your solution works at all!

Shouldn't you get 

A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.

???

The only difference between your example and my usage scenario is that I get my data from my database, whereas yours is hard coded.
So, shouldn't yours also fail?
Tags
Grid
Asked by
Ramesh
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ramesh
Top achievements
Rank 1
ROB
Top achievements
Rank 1
Stefan Vantchev
Top achievements
Rank 1
Share this question
or