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
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:
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 >>
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
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 >>
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
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.
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 >>
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
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.
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 >>
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
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 >>
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
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 >>
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
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
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.
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 >>
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);
}
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?