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

Grid data in cells shows as "undefined"

3 Answers 1545 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 17 Dec 2014, 06:25 AM
I have the following object for configuration and code, but when the grid renders, the column headers look fine...but the rows show up as a single row of "undefined" repeated for each entry.  Please help.

configuration object:
{"dataSource":{"data":[{"s":"http://en.wikipedia.org/wiki/Une_Histoire_de_vent","o":"en","p":"http://purl.org/dc/elements/1.1/language","id":0},{"p":"http://www.w3.org/1999/02/22-rdf-syntax-ns#type","s":"http://en.wikipedia.org/wiki/Une_Histoire_de_vent","o":"http://xmlns.com/foaf/0.1/Document","id":1},{"o":"http://dbpedia.org/resource/Une_Histoire_de_vent","s":"http://en.wikipedia.org/wiki/Une_Histoire_de_vent","p":"http://xmlns.com/foaf/0.1/primaryTopic","id":2},{"p":"http://www.w3.org/2002/07/owl#someValuesFrom","s":"b0","o":"http://www.w3.org/2006/03/wn/wn20/schema/AdverbWordSense","id":3},{"s":"b0","o":"http://www.w3.org/2006/03/wn/wn20/schema/containsWordSense","p":"http://www.w3.org/2002/07/owl#onProperty","id":4},{"p":"http://www.w3.org/1999/02/22-rdf-syntax-ns#type","o":"http://www.w3.org/2002/07/owl#Restriction","s":"b0","id":5},{"o":"http://xmlns.com/foaf/0.1/Document","s":"http://en.wikipedia.org/wiki/2006_White_House_Correspondents'_Association_Dinner","p":"http://www.w3.org/1999/02/22-rdf-syntax-ns#type","id":6},{"p":"http://purl.org/dc/elements/1.1/language","s":"http://en.wikipedia.org/wiki/2006_White_House_Correspondents'_Association_Dinner","o":"en","id":7},{"p":"http://xmlns.com/foaf/0.1/primaryTopic","s":"http://en.wikipedia.org/wiki/2006_White_House_Correspondents'_Association_Dinner","o":"http://dbpedia.org/resource/2006_White_House_Correspondents'_Association_Dinner","id":8},{"o":"http://www.w3.org/2006/03/wn/wn20/schema/WordSense","s":"b1","p":"http://www.w3.org/2002/07/owl#someValuesFrom","id":9}],"pageSize":25,"schema":{"model":{"fields":[{"s":{"type":"string"}},{"p":{"type":"string"}},{"o":{"type":"string"}}]}}},"height":400,"scrollable":true,"sortable":true,"filterable":true,"pageable":{"input":true,"numeric":false},"columns":[{"field":"s","title":"s"},{"field":"p","title":"p"},{"field":"o","title":"o"}]}

And here is my code:
        var columns = [];
        var fields = [];
        
        $.each(data.results.head.vars, function(index, value) {
          columns.push({'field': value, 'title': value});
          var to = {};
          to[value] = {type: "string"};
          fields.push(to);
        });
        
        var dataBindings = [];
        $.each(data.results.results.bindings, function(index1, value) {
          var tempobj = {};
          $.each(value, function(k1,v1) {
            tempobj[k1] = v1.value;
          });
          tempobj.id=index1;
          dataBindings.push(tempobj);
        });
        
        console.log(JSON.stringify(dataBindings));
        var configuration = {
          dataSource: {
            data: dataBindings,
            pageSize: 25,
            schema: {
              model: {
                fields: fields
              }
            },
          },
          height: 400,
          scrollable: true,
          sortable: true,
          filterable: true,
          pageable: {
            input: true,
            numeric: false
          },
          'columns': columns
        };
        
        console.log(JSON.stringify(configuration));
        
        // Create the popup window
        var gridWindow = $("#resultsPopup").kendoWindow({
          width: "70%",
          title: "Graph Results",
          actions: [
              "Minimize",
              "Maximize",
              "Close"
          ]
        }).data('kendoWindow');
        
        gridWindow.center().open();
        
        // Create the grid
        var grid = $("#resultsGrid").kendoGrid(configuration).data('kendoGrid');

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 18 Dec 2014, 04:50 PM
Hello Aaron,

The issue you have described is due to the use of the o as field name in the object. A variable with the same name is used within the generated code for kendo.template - which are used at multiple places during the widgets rendering. This collision will cause the item to be overridden thus, the undefined is displayed. Therefore, I suggest you to change the name of the field to something different.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Aaron
Top achievements
Rank 1
answered on 18 Dec 2014, 05:02 PM
Got it!  I changed the JSON key to "obj" and that worked.  One issue, though, is that this is the result of a free form query that I cannot really control other than maybe a messy popup that would warn against using the reserved "o".  If I detect if that exists in the data and then rename it, would that do the trick?  Or is there some other workaround?

The user could write a query like this:

SELECT ?s ?p ?o
WHERE {
  ?s ?p ?o .
}
LIMIT 500

I could not prevent them from doing this...other than a warning and/or do the rewrite during the rest of my munging process seen previously in the code.  consequently, the variable "o" is likely to be one of the most commonly used ones as most tutorials for SPARQL queries use that convention...though it is not necessary.  Your thoughts on the best way to handle this?
0
Rosen
Telerik team
answered on 19 Dec 2014, 09:33 AM
Hello Aaron,

Indeed, renaming the data prior to assigning it to Grid should workaround the issue.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Aaron
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Aaron
Top achievements
Rank 1
Share this question
or