Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html lang="en" ng-app="demoApp">

<head>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>Demo</title>

  <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" href="https://rawgit.com/daniel-nagy/md-data-table/master/dist/md-data-table.css">

</head>

<body layout="column">

  <md-toolbar class="md-whiteframe-1dp">
    <div class="md-toolbar-tools">
      <div class="md-title">Material Design Data Table</div>
    </div>
  </md-toolbar>

  <md-content laout="column" flex ng-controller="nutritionController">
    <md-card>

      <md-toolbar class="md-table-toolbar md-default" ng-hide="selected.length">
        <div class="md-toolbar-tools">
          <span>Nutrition</span>
        </div>
      </md-toolbar>

      <md-toolbar class="md-table-toolbar alternate" ng-show="selected.length">
        <div class="md-toolbar-tools">
          <span>{{selected.length}} {{selected.length > 1 ? 'items' : 'item'}} selected</span>
        </div>
      </md-toolbar>
      
      <md-virtual-repeat-container ng-style='listStyle' fix-head>  
        <md-table-container>
          <table md-table md-row-select ng-model="selected" md-progress="promise">
            <thead md-head md-order="query.order">
              <tr md-row>
                <th md-column md-order-by="name"><span>Dessert (100g serving)</span></th>
                <th md-column md-order-by="type"><span>Type</span></th>
                <th md-column md-numeric md-order-by="calories.value" md-desc><span>Calories</span></th>
                <th md-column md-numeric md-order-by="fat.value"><span>Fat (g)</span></th>
                <th md-column md-numeric md-order-by="carbs.value"><span>Carbs (g)</span></th>
                <th md-column md-numeric md-order-by="protein.value"><span>Protein (g)</span></th>
                <th md-column md-numeric md-order-by="sodium.value" hide-gt-xs show-gt-md><span>Sodium (mg)</span></th>
                <th md-column md-numeric md-order-by="calcium.value" hide-gt-xs show-gt-lg><span>Calcium (%)</span></th>
                <th md-column md-numeric md-order-by="iron.value" hide-gt-xs show-gt-lg><span>Iron (%)</span></th>
                <th md-column md-order-by="comment">
                  <md-icon>comments</md-icon>
                  <span>Comments</span>
                </th>
              </tr>
            </thead>
            <tbody md-body>
              <tr md-row md-select="dessert" md-auto-select md-virtual-repeat="dessert in dynamicItems" md-on-demand>
                <td md-cell>{{dessert.name}}</md-cell>
                  <td md-cell>
                    <md-select ng-model="dessert.type" placeholder="Other">
                      <md-option ng-value="type" ng-repeat="type in getTypes()">{{type}}</md-option>
                    </md-select>
                    </md-cell>
                    <td md-cell>{{dessert.calories.value}}</td>
                    <td md-cell>{{dessert.fat.value | number: 2}}</td>
                    <td md-cell>{{dessert.carbs.value}}</td>
                    <td md-cell>{{dessert.protein.value | number: 2}}</td>
                    <td md-cell hide-gt-xs show-gt-md>{{dessert.sodium.value}}</td>
                    <td md-cell hide-gt-xs show-gt-lg>{{dessert.calcium.value}}%</td>
                    <td md-cell hide-gt-xs show-gt-lg>{{dessert.iron.value}}%</td>
                    <td md-cell ng-click="editComment($event, dessert)" ng-class="{'md-placeholder': !dessert.comment}">
                      {{dessert.comment || 'Add a comment'}}
                    </td>
              </tr>
            </tbody>
          </table>
        </md-table-container>
      </md-virtual-repeat-container>
    </md-card>
  </md-content>

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
  <script src="https://rawgit.com/daniel-nagy/md-data-table/master/dist/md-data-table.js"></script>
  <script src="https://rawgit.com/enigmatic/fixed-table-header/master/src/fixed-table-header.js"></script>

</body>

</html>
              
            
!

CSS

              
                body,
md-content {
  background-color: #f5f5f5 !important;
}

body > md-toolbar {
  z-index: 3;
}

md-toolbar.md-table-toolbar.alternate {
  color: #1e88e5;
  background-color: #e3f2fd;
}

md-toolbar.md-table-toolbar.alternate .md-toolbar-tools {
  font-size: 16px;
}

md-virtual-repeat-container {
  height: 300px;
}

              
            
!

JS

              
                angular.module('demoApp', ['ngMaterial', 'md.data.table', 'fixed.table.header'])

.config(['$mdThemingProvider', function($mdThemingProvider) {
  'use strict';

  $mdThemingProvider.theme('default')
    .primaryPalette('blue');
}])

.controller('nutritionController', ['$mdEditDialog', '$scope', '$timeout', function($mdEditDialog, $scope, $timeout) {
  'use strict';

  $scope.selected = [];

  $scope.query = {
    order: 'name',
    limit: 10
  };

  $scope.desserts = {
    "count": 9,
    "data": [{
      "name": "Frozen yogurt",
      "type": "Ice cream",
      "calories": {
        "value": 159.0
      },
      "fat": {
        "value": 6.0
      },
      "carbs": {
        "value": 24.0
      },
      "protein": {
        "value": 4.0
      },
      "sodium": {
        "value": 87.0
      },
      "calcium": {
        "value": 14.0
      },
      "iron": {
        "value": 1.0
      }
    }, {
      "name": "Ice cream sandwich",
      "type": "Ice cream",
      "calories": {
        "value": 237.0
      },
      "fat": {
        "value": 9.0
      },
      "carbs": {
        "value": 37.0
      },
      "protein": {
        "value": 4.3
      },
      "sodium": {
        "value": 129.0
      },
      "calcium": {
        "value": 8.0
      },
      "iron": {
        "value": 1.0
      }
    }, {
      "name": "Eclair",
      "type": "Pastry",
      "calories": {
        "value": 262.0
      },
      "fat": {
        "value": 16.0
      },
      "carbs": {
        "value": 24.0
      },
      "protein": {
        "value": 6.0
      },
      "sodium": {
        "value": 337.0
      },
      "calcium": {
        "value": 6.0
      },
      "iron": {
        "value": 7.0
      }
    }, {
      "name": "Cupcake",
      "type": "Pastry",
      "calories": {
        "value": 305.0
      },
      "fat": {
        "value": 3.7
      },
      "carbs": {
        "value": 67.0
      },
      "protein": {
        "value": 4.3
      },
      "sodium": {
        "value": 413.0
      },
      "calcium": {
        "value": 3.0
      },
      "iron": {
        "value": 8.0
      }
    }, {
      "name": "Jelly bean",
      "type": "Candy",
      "calories": {
        "value": 375.0
      },
      "fat": {
        "value": 0.0
      },
      "carbs": {
        "value": 94.0
      },
      "protein": {
        "value": 0.0
      },
      "sodium": {
        "value": 50.0
      },
      "calcium": {
        "value": 0.0
      },
      "iron": {
        "value": 0.0
      }
    }, {
      "name": "Lollipop",
      "type": "Candy",
      "calories": {
        "value": 392.0
      },
      "fat": {
        "value": 0.2
      },
      "carbs": {
        "value": 98.0
      },
      "protein": {
        "value": 0.0
      },
      "sodium": {
        "value": 38.0
      },
      "calcium": {
        "value": 0.0
      },
      "iron": {
        "value": 2.0
      }
    }, {
      "name": "Honeycomb",
      "type": "Other",
      "calories": {
        "value": 408.0
      },
      "fat": {
        "value": 3.2
      },
      "carbs": {
        "value": 87.0
      },
      "protein": {
        "value": 6.5
      },
      "sodium": {
        "value": 562.0
      },
      "calcium": {
        "value": 0.0
      },
      "iron": {
        "value": 45.0
      }
    }, {
      "name": "Donut",
      "type": "Pastry",
      "calories": {
        "value": 452.0
      },
      "fat": {
        "value": 25.0
      },
      "carbs": {
        "value": 51.0
      },
      "protein": {
        "value": 4.9
      },
      "sodium": {
        "value": 326.0
      },
      "calcium": {
        "value": 2.0
      },
      "iron": {
        "value": 22.0
      }
    }, {
      "name": "KitKat",
      "type": "Candy",
      "calories": {
        "value": 518.0
      },
      "fat": {
        "value": 26.0
      },
      "carbs": {
        "value": 65.0
      },
      "protein": {
        "value": 7.0
      },
      "sodium": {
        "value": 54.0
      },
      "calcium": {
        "value": 12.0
      },
      "iron": {
        "value": 6.0
      }
    }]
  };

  $scope.editComment = function(event, dessert) {
    event.stopPropagation(); // in case autoselect is enabled

    var editDialog = {
      modelValue: dessert.comment,
      placeholder: 'Add a comment',
      save: function(input) {
        if (input.$modelValue === 'Donald Trump') {
          return $q.reject();
        }
        if (input.$modelValue === 'Bernie Sanders') {
          return dessert.comment = 'FEEL THE BERN!'
        }
        dessert.comment = input.$modelValue;
      },
      targetEvent: event,
      title: 'Add a comment',
      validators: {
        'md-maxlength': 30
      }
    };

    var promise = $mdEditDialog.small(editDialog);

    promise.then(function(ctrl) {
      var input = ctrl.getInput();

      input.$viewChangeListeners.push(function() {
        input.$setValidity('test', input.$modelValue !== 'test');
      });
    });

  };

  $scope.getTypes = function() {
    return ['Candy', 'Ice cream', 'Other', 'Pastry'];
  };
  //from https://material.angularjs.org/latest/demo/virtualRepeat
  var DynamicItems = function() {
    /**
     * @type {!Object<?Array>} Data pages, keyed by page number (0-index).
     */
    this.loadedPages = {};
    /** @type {number} Total number of items. */
    this.numItems = 0;
    /** @const {number} Number of items to fetch per request. */
    this.PAGE_SIZE = $scope.desserts.count;
    this.fetchNumItems_();
  };
  // Required.
  DynamicItems.prototype.getItemAtIndex = function(index) {
    
    var pageNumber = Math.floor(index / this.PAGE_SIZE);
    var page = this.loadedPages[pageNumber];
    if (page) {
      return page[index % this.PAGE_SIZE];
    } else if (page !== null) {
      this.fetchPage_(pageNumber);
    }
  };

  // Required.
  DynamicItems.prototype.getLength = function() {
    return this.numItems;
  };
  DynamicItems.prototype.fetchPage_ = function(pageNumber) {
    // Set the page to null so we know it is already being fetched.
    this.loadedPages[pageNumber] = null;
    // For demo purposes, we simulate loading more items with a timed
    // promise. In real code, this function would likely contain an
    // $http request.
    $timeout(angular.noop, 3000).then(angular.bind(this, function() {
      this.loadedPages[pageNumber] = $scope.desserts.data;
    }));
  };
  DynamicItems.prototype.fetchNumItems_ = function() {
    // For demo purposes, we simulate loading the item count with a timed
    // promise. In real code, this function would likely contain an
    // $http request.
    $timeout(angular.noop, 1000).then(angular.bind(this, function() {
      this.numItems = 50000;
    }));
  };
  $scope.dynamicItems = new DynamicItems();

}]);
              
            
!
999px

Console