var testing = new kendo.data.DataSource({
// data: [{name:"test", type: "user",description: "A user"}]
transport: {
read: {
url: "/api/testing",
dataType: "json"
}
}
});
$("#overviewGrid").kendoGrid({
dataSource: testing,
columns: [ { title: "Name", field: "name" },
{ title: "Type", field: "type"},
{ title: "Description", field: "description" } ]
});
The results form /api/testing are:
[{name:"test", type: "user",description: "A user"}]
When this runs, I get the exception specified in the title (Uncaught ReferenceError: uid is not defined).
If I comment out the transport option of the dataSource and instead use the hardcoded data node, it works perfectly.
Any help on what I'm doing wrong?
18 Answers, 1 is accepted
I tried to reproduce this but to no avail. Here is my test jsfiddle: http://jsfiddle.net/korchev/qUgy4/3/
Is there anything else in your page which may lead to this problem?
I've also noticed that your result is not valid JSON. The keys should be quoted like this:
[{ "name":"test", "type": "user", "description": "A user"}]
Atanas Korchev
the Telerik team
instead of:
[{"description":"A user","name":"test","type":"user"}]
It was returning:
"[{"description":"A user","name":"test","type":"user"}] "
Thanks for the help!
function anonymous(data) {
var o,e=kendo.htmlEncode;with(data){o='<tr class="k-master-row" data-uid="'+(uid)+'"><td class="k-hierarchy-cell"><a class="k-icon k-plus" href="#"></a></td><td>'+(e(Proj_code))+'</td><td>'+(e(Proj_name))+'</td><td>'+(e(Proj_type))+'</td><td>'+(e(kendo.format("{0:C0}",Fee_contract)))+'</td><td>'+(e(PM_emp_id))+'</td><td>'+(e(CM_emp_id))+'</td><td>'+(e(kendo.format("{0:C0}",Rem_budget)))+'</td><td>'+(e(kendo.format("{0:C0}",Contracted_fees)))+'</td></tr>';}return o;
}
'uid' is undefined
Checked json result and it is in good form.
How does your data look like?
All the best,Atanas Korchev
the Telerik team
[{"Proj_code":"11111111 ","Month_year":"201204","Proj_name":"Acme Retainer","Proj_type":"Acme Retainer_ABC_123 ","Prac_area":"ABC ","Acct_team":"JJJJJJ ","Prod_team":"QRS ","Fee_contract":139154.8400,"Rem_budget":-58762.9600,"Req_fee_adj":0.0000,"Tot_fee_adj":-9497.4500,"Cur_mo_pred":0.0000,"Cur_mo_act":5000.0000,"Next_mo_1":0.0000,"Next_mo_2":0.0000,"Block_mo_3":0.0000,"Block_mo_4":0.0000,"Block_mo_5":0.0000,"Block_mo_6":0.0000,"Block_mo_7":0.0000,"Block_mo_8":0.0000,"Block_mo_9":0.0000,"Block_mo_10":0.0000,"Block_mo_11":0.0000,"PM_emp_id":"50864 ","CM_emp_id":"12345 ","PC_emp_id":"54321 ","Signature":null,"Last_change_date":null,"Contracted":0,"PO":0,"Client_name":"Acme, Inc.","Contracted_fees":null},
{ NEXT ONE HERE },
{ ETC },
]
Thanks
I tried to reproduce this problem to no avail. Here is my test jsFiddle: http://jsfiddle.net/korchev/K3c9T/1/
What is different in your case?
Atanas Korchev
the Telerik team
JSON Data being returned:
[{"code":"4f92742ab878e","num":1021318995,"id":0},{"code":"4f92742ab87d4","num":176528002,"id":1},{"code":"4f92742ab8817","num":200150905,"id":2},{"code":"4f92742ab885a","num":1912918525,"id":3},{"code":"4f92742ab889d","num":1068454143,"id":4},{"code":"4f92742ab88e0","num":30497630,"id":5},{"code":"4f92742ab8923","num":274510480,"id":6},{"code":"4f92742ab8966","num":194362464,"id":7},{"code":"4f92742ab89a9","num":940865948,"id":8},{"code":"4f92742ab89ec","num":307123023,"id":9}]
Code to initialise the grid:
$("#myGrid").kendoGrid({
columns: [
{ title: "ID", field: "id" },
{ title: "Unique Code", field: "code" },
{ title: "Number", field: "num" }
],
dataSource: {
transport: {
read: "data/person.json"
}
}
});
Not complicated at all. But I've tried much more complicated definitions without success. What am I missing? :(
I'm not able to recreate such error locally. Please check this jsFiddle page.
Greetings,Rosen
the Telerik team
dataSource: { transport: { read:{ dataType: "json", url: "data/person.json" } }}After that, it just started working. Without the dataType option it just throws javascript errors, but with it, it works brilliantly.
It appears that setting the read transport dataType option to "json" actually requests a JSON document (firebug shows JSON instead of HTML). I'm assuming this means the data now ends up as an object instead of a string when initialising the grid. Just an uneducated guess though.
$(document).ready(function () {
var ds = new kendo.data.DataSource({
transport: {
read: {
url: "Kendo.aspx/ReturnTOPData",
dataType: "json"
}
}
});
$("#grid").kendoGrid({
dataSource: ds,
columns: [
{ title: "SiteID", field: "SiteID", width: 30 },
{ title: "Site", field: "Site", width: 130}],
height: 550,
groupable: false,
scrollable: true,
sortable: true,
pageable: true
});
});
My JSON is:
[{"SiteID":"1","Site":"Niagara"},{"SiteID":"2","Site":"Endeavor"},{"SiteID":"3","Site":"Adam"},{"SiteID":"4","Site":"Jeffers"},{"SiteID":"5","Site":"SilverStar"},{"SiteID":"6","Site":"TaconiteRidge"},{"SiteID":"7","Site":"Cohocton"},{"SiteID":"8","Site":"EdomHills"},{"SiteID":"9","Site":"Endeavor2"},{"SiteID":"10","Site":"CrystalLake"},{"SiteID":"11","Site":"Fowler"},{"SiteID":"12","Site":"FlatRidge/BP"},{"SiteID":"13","Site":"Milford"},{"SiteID":"14","Site":"Sheffield"},{"SiteID":"16","Site":"HighLonesome"},{"SiteID":"17","Site":"FlatRidge/Westar"},{"SiteID":"18","Site":"La Mata & La Ventosa"},{"SiteID":"19","Site":"Titan"},{"SiteID":"20","Site":"Fuerza Eolica"},{"SiteID":"21","Site":"Kahuku"},{"SiteID":"22","Site":"Criterion"},{"SiteID":"23","Site":"Community Wind North"},{"SiteID":"24","Site":"Sherbino"},{"SiteID":"25","Site":"Trinity Hills"},{"SiteID":"26","Site":"GL Wind 1"},{"SiteID":"27","Site":"Eolos"},{"SiteID":"28","Site":"Fuerza Eolica 2"},{"SiteID":"29","Site":"Niagara2"},{"SiteID":"30","Site":"Kirkwood"}]
I tried to reproduce this error to no avail. Here is my jsFiddle: http://jsfiddle.net/korchev/ECG4L/1/
Do you see any other errors? Could you open a support ticket and send us a running project which we can troubleshoot?
Atanas Korchev
the Telerik team
What I can show you is the code that is run to return the string:
Imports System.DataImports System.Web.Script.ServicesImports System.Web.ServicesImports System.Web.Script.SerializationPartial Class Kendo Inherits System.Web.UI.Page <ScriptMethod()> _ <WebMethod()> _ Public Shared Function ReturnTOPData() As String Dim dt As New DataTable 'Datatable information omitted. Dim cnt As Integer = dt.Rows.Count Dim tsite(dt.Rows.Count - 1) As SitesGroup For i As Integer = 0 To cnt - 1 tsite(i) = New SitesGroup() tsite(i).SiteID = dt.Rows(i).Item("siteid") tsite(i).Site = dt.Rows(i).Item("sitename") Next Dim js As New JavaScriptSerializer() Dim tc As String = js.Serialize(tsite) Return tc End FunctionEnd ClassPublic Class SitesGroup Private _siteid As String Public Property SiteID() As String Get Return _siteid End Get Set(value As String) _siteid = value End Set End Property Private _site As String Public Property Site() As String Get Return _site End Get Set(value As String) _site = value End Set End PropertyEnd ClassA very easy way to test for this, is to run google chrome, launch the javascript console and choose the 'Network' tab. Refresh your page and you should see a call to your webservice. Choose that and the 'response' tab. This shows you exactly what the webservice is returning.
The problem is indeed that you are serializing manually your data as JSON. As Kyle pointed out you should return your object without serializing it:
<ScriptMethod()> _<WebMethod()> _Public Shared Function ReturnTOPData() As SitesGroup Dim dt As New DataTable'Datatable information omitted. Dim cnt As Integer = dt.Rows.Count Dim tsite(dt.Rows.Count - 1) As SitesGroup For i As Integer = 0 To cnt - 1 tsite(i) = New SitesGroup() tsite(i).SiteID = dt.Rows(i).Item("siteid") tsite(i).Site = dt.Rows(i).Item("sitename") Next Return tsiteEnd FunctionHere you can find a working example showing binding the Kendo Grid to an ASMX web service: https://github.com/telerik/kendo-examples-asp-net/tree/master/grid-web-service-crud
You may also find interesting this blog post: http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/
It shows how to consume JSON web services from jQuery (which is how the Kendo DataSource works under the hood): All the best,
Atanas Korchev
the Telerik team
I did a detailed walk though for them to fix the issue including jsfiddle examples.
http://www.kendoui.com/forums/ui/grid/grid-with-template-error-uncaught-referenceerror-sum-is-not-define.aspx#2232854
I also suggested they fix they template to handle for null data or data with columns with weird names.
The key is that the system could break in many ways give the template errors i point out. They will argue because i have seen in amny posts that the data is at fault.
But there's and data-tables.net are the only two that had this error of the 8 i tested and one i made from hand. Its a deal breaker for me i need it fixed, i would love to use them,but cant if i cant trust the default template.
http://kendo.uservoice.com/forums/127393-kendo-ui-feedback/suggestions/3079391-making-the-data-grid-template-more-stable-and-less