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.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

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.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                <div class="container" ng-app="myApp">
   <div  ng-controller="ctrl">
      <div class="panel panel-default data-table">
         <div class="panel-heading">
            <ul class="nav nav-pills">
               <li role="presentation" ng-class="{'active': targetTable == t}" ng-repeat="t in tables"><a href="#" ng-click="select(t)">{{t.name}}</a></li>
               <li><a href="#" ng-click="select(t)">+ Add Table</a></li>
            </ul>
         </div>
         <div class="panel-body">
            <table class="table table-bordered">
               <colgroup>
                  <col class="unique-id">
               </colgroup>
               <thead>
                  <tr>
                     <th class="unique-id">ID #</th>
                     <th contenteditable="true" ng-repeat="c in targetTable.columns" ng-model="c.label"></th>
                     <th class="view-next-set"><a href="#">...</a></th>
                     <td class="center add-column"><a href="#" ng-click="addColumn()">+ Add Column</a></td>
                  </tr>
               </thead>
               <tbody>
                  <tr ng-repeat="r in targetTable.rows">
                     <td class="unique-id">{{r.id}}</td>
                     <td contenteditable="true" ng-repeat="column in targetTable.columns" ng-model="r[column.id]" ng-blur="!r.id? addNewRow(r[column.id], r): undefined"></td>
                     <td class="blank" colspan="2"></td>
                  </tr>
                 <!--<tr>
                     <td class="unique-id"></td>
                     <td contenteditable="true" ng-repeat="column in targetTable.columns" ng-model="entry" ng-blur="addRow(entry, column.id)"></td>
                     <td class="blank" colspan="2"></td>
                  </tr> -->
               </tbody>
            </table>
         </div>
      </div>
     <div class="well well-sm"><code>{{read()}}</code></div>
     
      
   </div>
</div>
              
            
!

CSS

              
                body { margin:60px 0px; }

.data-table .nav-pills li { text-transform: capitalize; }
.nav.nav-pills li span { padding: 20px; }
.table .unique-id { width: 10px !important; text-align: center; background-color:#f5f5f5; }
.table td, .table th { width: 120px; }
.table .center { text-align: center; }
.table th.font-normal { font-weight: normal; }
.table .view-next-set { width:5px; text-align:center; font-size:0.9em; }
.table .add-column { width:60px; font-size:1em; vertical-align: middle; }

.table .unique-id, .table td.blank { background-color:#f5f5f5; }
              
            
!

JS

              
                // Define the `ReportsMockUpsApp` module
angular.module('customControl', ['ngSanitize']).
directive('contenteditable', ['$sce', function($sce) {
  return {
    restrict: 'A', // only activate on element attribute
    require: '?ngModel', // get a hold of NgModelController
    link: function(scope, element, attrs, ngModel) {
      var disable = (attrs.contenteditable === "false") || !Boolean(attrs.contenteditable);
      if (!ngModel || disable) return; // do nothing if no ng-model
      
      // Write data to the model
      var read = function(value) {
        var html = element.html() || (typeof value === "string"? value: "");
        
        // When we clear the content editable the browser leaves a <br> behind
        // If strip-br attribute is provided then we strip this out
        if ( attrs.stripBr && html == '<br>' ) { html = ''; }
        ngModel.$setViewValue(html);
      };  

      // Specify how UI should be updated
      ngModel.$render = function() {
        element.html($sce.getTrustedHtml(ngModel.$viewValue || ''));
      };

      // Listen for change events to enable binding
      element.on('blur keyup change', function() {
        scope.$evalAsync(read);
      });
      
      setTimeout(function(){
        read(ngModel.$modelValue); // initialize
      });
      
    }
  };
}]);


var app = angular.module('myApp', ['customControl']);

// Define the `appController` controller on the `ReportsMockUpsApp` module
app.controller('ctrl', function($scope) {
   var table =  {
     id: 0,
     name: "table 14",
     columns: [{id: 0, label:"Name"}, {id: 1, label:"Age"}],
     rows: [{"0": "Mark Smith", "1": 10, id: 1035}, {"0": "Mathew Coley", "1": 54, id: 1036}, {}],
     uniqueIdCounter: 1037
   };
  
   $scope.tables = [table];  
   $scope.targetTable = $scope.tables[0];
  
  $scope.select = function(tbl) {
    $scope.selectedTable = tbl;
  };
  
  $scope.addColumn = function() {
    var columns = $scope.targetTable.columns, id = columns.length;
    $scope.targetTable.columns.push({
      id: columns.length, 
      label: `Column ${id}`
    });
  };  

  
  $scope.addNewRow = function(value, row) { 
    if(!value || value === "" || typeof value !== 'string') return;
    $scope.targetTable.rows.push({});
    debugger;
    row.id = $scope.targetTable.uniqueIdCounter++;
  };
  
   /*$scope.addRow = function(value, column) {    
    if(!value || value === "" || typeof value !== 'string') return;
    else if(column === "") return;
    
    // create new row
    var row = { id: 2000 };
    row[column] = value;
    $scope.targetTable.rows.push(row); 
    
    // clear last row cell..
    this.entry = "";   
    debugger;
  };*/
  
  
  
  /*$scope.viewColumns = function(start, end) {
    var columns = [];
    for (var i = min; i <= max; i ++) {
        columns.push(i);
    }
    return input;
  };*/
  
  $scope.read = function(){
    return JSON.stringify(table);
  };
  
});

              
            
!
999px
Save your sass for CSS. Everywhere else be kind.

Console