angularjskendo-ui

Creating a basic data grid with Kendo UI and AngularJS


I'm experimenting with AngularJS. I want to show a basic Kendo Grid. I'm trying to do this using pure directives. With that in mind, I've looked at the Kendo UI / Angular JS project (https://github.com/kendo-labs/angular-kendo). Unfortunately, my

index.html:

<div>Products: {{products.length}}</div>
<div kendo-grid k-data-source="products" k-selectable="'row'"
  k-pageable='{ "refresh": true, "pageSizes": true }'
  k-columns='[
    { "field": "Name", "title": "Name"},
    { "field": "Department", "title": "Department"},
    { "field": "LastShipment", "title": "Last Shipment" }
  ]'>
</div>

controllers.js

function myController($scope) {
    console.log("initializing controller...");
    $scope.products = [
        { id:1, name:'Tennis Balls', department:'Sports', lastShipment:'10/01/2013' },
        { id:2, name:'Basket Balls', department:'Sports', lastShipment:'10/02/2013' },
        { id:3, name:'Oil', department:'Auto', lastShipment:'10/01/2013' },
        { id:4, name:'Filters', department:'Auto', lastShipment:'10/01/2013' },
        { id:5, name:'Dresser', department:'Home Furnishings', lastShipment:'10/01/2013' }
    ];
}

I've verified that I've wired up the controller properly. The activity count shows properly. However, the grid does not appear. I can't figure out what I'm doing incorrectly.

Thank you for your help.


Solution

  • It looks as if the field names are spelled wrong. The following works for me:

    <div kendo-grid k-data-source="products" k-selectable="'row'"
    k-pageable='{ "pageSize": 2, "refresh": true, "pageSizes": true }'
      k-columns='[
        { "field": "name", "title": "Name"},
        { "field": "department", "title": "Department"},
        { "field": "lastShipment", "title": "Last Shipment" }
      ]'>
    </div>
    

    Here is a live demo: http://jsbin.com/odeQAfI/2/edit

    To avoid the NaN message in the pager you need to make the products field to be a Kendo DataSource:

    function MyController($scope) {
       $scope.products = new kendo.data.DataSource({ 
         data: [
            { id:1, name:'Tennis Balls', department:'Sports', lastShipment:'10/01/2013' },
            { id:2, name:'Basket Balls', department:'Sports', lastShipment:'10/02/2013' },
            { id:3, name:'Oil', department:'Auto', lastShipment:'10/01/2013' },
            { id:4, name:'Filters', department:'Auto', lastShipment:'10/01/2013' },
            { id:5, name:'Dresser', department:'Home Furnishings', lastShipment:'10/01/2013' }
        ],
         pageSize: 2
      });
    }
    

    Here is a live demo: http://jsbin.com/ODElUfO/2/edit