When I try and call .dataBind() on a Telerik Grid object in javascript, it throws an exception. The same code I'm using was working just fine with a previous version of the Telerik controls (2010.2.930) but since the update (using NuGet) to the latest version (2011.2.712), the code has broken.
These are the various errors on different browsers.
Firefox 6: this.dataSource is undefined (telerik.grid.min.js - line 1)
Chrome 13: Uncaught TypeError: Cannot call method 'success' of undefined (telerik.grid.min.js:1) IE 9: SCRIPT5007: Unable to get value of the property 'success': object is null or undefined (telerik.grid.min.js, line 1 character 25697)I have managed to create a very simple repo, all you need to do is put this in a fresh page:
<div>
@(Html.Telerik().Grid(new List<GridData>())
开发者_如何学Go .Name("TestGrid")
.Columns(column =>
{
column.Bound(e => e.Name).Title("Name").Width("9em");
column.Bound(e => e.Description).Title("Description").Width("9em");
}))
</div>
<p>
<a id="getData" href="#">Bind Data</a>
</p>
<script type="text/javascript">
(function ($) {
$(document).ready(function () {
$('#getData').click(bindGridData);
});
})(jQuery);
var bindGridData = function() {
var grid = $("#TestGrid").data("tGrid");
var testData = [
{ Name: "Name 1", Description: "Description 1" },
{ Name: "Name 2", Description: "Description 2" }
];
grid.dataBind(testData);
};
</script>
The GridData class is just a simple POCO with Name and Description string properties.
Seems like it was a bug in their code. I issued a support ticket with Telerik and they gave me a hotfix.
Unfortunately I can't link to it because it's a private message. BUT, don't fear, I did manage to find a link to it on a public forum page:
http://www.telerik.com/community/forums/aspnet-mvc/general/gridroutevalues-allowhtml.aspx
If that doesn't work you can always wait until it's fixed in the next NuGet drop.
精彩评论