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

Uncaught ReferenceError: uid is not defined

18 Answers 2625 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 03 Apr 2012, 03:12 PM
I'm trying to load json data via a webservice, using the following code:

            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

Sort by
0
Atanas Korchev
Telerik team
answered on 03 Apr 2012, 03:26 PM
Hello,

 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"}]  

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kyle
Top achievements
Rank 1
answered on 03 Apr 2012, 05:03 PM
Ah, I got it figured out. My result was putting quotes around the entire JSON result.

instead of:

[{"description":"A user","name":"test","type":"user"}] 

It was returning:

"[{"description":"A user","name":"test","type":"user"}] "

Thanks for the help!
0
LHill
Top achievements
Rank 1
answered on 10 Apr 2012, 02:23 PM
Same issue, only happens in IE8, works fine in Safari, Firefox, Opera, Chrome

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.
0
Atanas Korchev
Telerik team
answered on 10 Apr 2012, 02:24 PM
Hello,

 How does your data look like?

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
LHill
Top achievements
Rank 1
answered on 10 Apr 2012, 03:42 PM
Here is a snippet, I can email you the file if you want the whole thing - don't want to post.

[{"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
0
Atanas Korchev
Telerik team
answered on 10 Apr 2012, 04:16 PM
Hi,

 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? 

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jamie
Top achievements
Rank 1
answered on 21 Apr 2012, 09:49 AM
I'm actually getting this exact same error.   I'm still testing out Kendo to see if can do what I need, so my data is all randomly generated.

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? :(
0
Rosen
Telerik team
answered on 24 Apr 2012, 07:37 AM
Hi Jamie,

I'm not able to recreate such error locally. Please check this jsFiddle page.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jamie
Top achievements
Rank 1
answered on 24 Apr 2012, 07:43 AM
I actually figured it out for myself yesterday and haven't had a chance to post up my fix.  All that was needed was, in the read transport, a dataType option needed to be set.  So my transport now looks like this.

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.
0
Nick
Top achievements
Rank 1
answered on 16 May 2012, 11:17 PM
I'm having this problem as well.  Copy/Pasted my returned JSON string into the data field and it works fine.  If I try to return it dynamically, I get the brush off.  I've already verified that the JSON string is correct and since the documentation is so sparse until Q2 comes out.

$(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"}]
0
Atanas Korchev
Telerik team
answered on 17 May 2012, 07:49 AM
Hello,

 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?

Kind regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Nick
Top achievements
Rank 1
answered on 17 May 2012, 04:28 PM
Yes, as I said, it works fine if you paste in the string into the code (which means it will work fine in jsFiddle as well).  I cannot send you a fully-functional project because I cannot include password to our database and we cannot run web services (it's against company policy since we are a GSA).  

What I can show you is the code that is run to return the string:

Imports System.Data
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Script.Serialization
 
 
Partial 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 Function
 
End Class
 
 
 
 
Public 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 Property
End Class
0
Kyle
Top achievements
Rank 1
answered on 17 May 2012, 04:49 PM
Your problem is that your webservice. You cannot return a string object, as .Net will take the json being generated by the serialization and wrap quotes around it making it invalid. Instead just return your SitesGroup object. .Net will take care of the serialization for you.
0
Nick
Top achievements
Rank 1
answered on 17 May 2012, 05:11 PM
I'm printing out the returned string and it is coming back without quotation marks wrapped around it.  At what point are they being added back in?
0
Kyle
Top achievements
Rank 1
answered on 17 May 2012, 05:21 PM
If your printing the string in your webmethod, then you will not see the quotes. It's somewhere in .Nets internals for handling string results from a webservice.

A 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.
0
Nick
Top achievements
Rank 1
answered on 17 May 2012, 10:18 PM
Yeah, I'm not allowed to run web services within my organization (per I.T.'s rules), so I won't be able to test in this fashion.  I am just going to finish up my KnockoutJS implementation for now (which is much easier to work with IMHO).  I don't have any additional time to waste on Kendo UI right now.  Thanks for trying to help though.
0
Atanas Korchev
Telerik team
answered on 18 May 2012, 09:11 AM
Hi,

 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 tsite
End Function

Here 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
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
joshua
Top achievements
Rank 1
answered on 15 Aug 2012, 05:48 PM
the error is because the columns in your data do not match:

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 
Tags
Data Source
Asked by
Kyle
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Kyle
Top achievements
Rank 1
LHill
Top achievements
Rank 1
Jamie
Top achievements
Rank 1
Rosen
Telerik team
Nick
Top achievements
Rank 1
joshua
Top achievements
Rank 1
Share this question
or