Premium forums

Error in very simple binding Grid to DataSource

  • Ivan Petrov
    Ivan Petrov avatar

    15 Jun 2012 (Link to this post)

    Hello! What's wrong with following code?

    <div id="grid"></div>
     
    <script type="text/javascript">
        $(function () {
     
            var units = [{ UnitId: 2 }, { UnitId: 5}];
     
            var ds = new kendo.data.DataSource({
                // transport: {
                //   read: { url: 'http://localhost:6356/admin/GetUnitTogglesList' }
                // },
                data: units
            });
     
            ds.read();                    // For test purpose:
            alert(ds.data().length);      // show 2 - it's Ok
     
            $('#grid').kendoGrid({
                dataSource: ds,
                columns: [{ title: "Unit Id", field: "UnitId"}]
            });
     
        });
    </script>

    In result - Grid is empty.
    And i see error in Firebug console (see attached image).
  • 15 Jun 2012 (Link to this post)

    Do you need the ds.read(); ?

    Also, have you tried defining the id in a schema property for the data source?
  • Ivan Petrov
    Ivan Petrov avatar

    19 Jun 2012 (Link to this post)

    Resolved.

    I use kendo.dataviz.min.js and kendo.web.js and error occurs if  web.js included before dataviz.js.

    I changed the order of the files and the problem disappeared.

    Correct order:

      <script src="kendo.dataviz.min.js" type="text/javascript"></script>
      <script src="kendo.web.js" type="text/javascript"></script>             // after dataviz!

Read FAQ or see Kendo UI in action!

Launch Demos