Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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-fluid">
  <h1>Latest Reports</h1>

  <!-- component template -->
  <script type="text/x-template" id="grid-template">
    <table class="table table-hover table-bordered table-striped">
      <thead>
        <tr>
          <th v-for="key in columns" @click="sortBy(key)" :class="{active: sortKey == key}">
            {{key | capitalize}}
            <span class="arrow" :class="sortOrders[key] > 0 ? 'asc' : 'dsc'">
          </span>
          </th>
          <th>Actions</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="
        entry in gdata
        | filterBy filterKey
        | orderBy sortKey sortOrders[sortKey]">
          <td class="small" v-for="key in columns">
            {{entry[key]}}
          </td>
          <td>
            <button class="btn btn-default" @click="deleterow(entry)">
                <span class="glyphicon glyphicon-delete" style="margin-top: 3px;"></span> Delete
                </button>
            <button class="btn btn-default" @click="editrow(entry)">Edit Post</button>
          </td>
        </tr>
      </tbody>
    </table>
    <alerta :show.sync="showRight" :duration=5000 type="info" width="400px" placement="top-right" dismissable>
      <span class="icon-ok-circled alert-icon-float-left"></span>
      <strong>Well Done!</strong>
      <p>You successfully removed the report.</p>
    </alerta>
    <new-edit-modal :show.sync="showNewEditModal"></new-edit-modal>
  </script>

  <!-- template for the Modal component -->
  <script type="x/template" id="modal-template">
    <div class="modal-mask" @click="close" v-show="show" transition="modal">
      <div class="modal-container" @click.stop>
        <slot></slot>
      </div>
    </div>
  </script>

  <!-- template for the NewPostModal component -->
  <script type="x/template" id="new-edit-modal-template">
    <modal :show.sync="show" :on-close="close">
      <div class="modal-header">
        <h3>Edit Report {{ id }}</h3>
      </div>

      <div class="modal-body">
        <label class="form-label">
                    Title
                    <input v-model="title" class="form-control">
                </label>
        <label class="form-label">
                    Body
                    <textarea v-model="body" rows="5" class="form-control"></textarea>
                </label>
      </div>

      <div class="modal-footer text-right">
        <button class="btn btn-default" @click="close">Cancel</button>
        <button class="btn btn-primary" class="modal-default-button" @click="savePost()">
                <span class="glyphicon glyphicon-save" style="margin-top: 3px;"></span> Save
                </button>
      </div>
    </modal>
  </script>

  <!-- demo root element -->
  <div id="demo">
    <form id="search">
      <div id="custom-search-input" style="padding-bottom: 15px;">
        <div class="input-group col-md-4">
          <input type="text" name="query" class="form-control input-sm" v-model="searchQuery" />
          <span class="input-group-btn">
                        <button class="btn btn-default btn-sm" type="button">
                            <i class="glyphicon glyphicon-search" style="margin-top: 3px;"></i>
                        </button>
                    </span>
        </div>
      </div>
    </form>

    <demo-grid :list="gridData" :columns="gridColumns" :filter-key="searchQuery">
    </demo-grid>

  </div>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                Vue.component('Modal', {
    template: '#modal-template',
    props: ['show', 'onClose'],
    methods: {
        close: function () {
            this.onClose();
        }
    },

    ready: function () {
        document.addEventListener("keydown", function(e) {
            if (this.show && e.keyCode == 27) {
                this.onClose();
            }
        })
    }
});

var editModal = Vue.component('NewEditModal', {
    template: '#new-edit-modal-template',
    props: ['show'],
    data: function () {
        return {
            id: '',
            title: '',
            body: ''
        };
    },

    methods: {
        close: function () {
            this.show = false;
            this.title = '';
            this.body = '';
            this.id = '';
        },

        refresh: function() {
            this.$dispatch('refreshReports');
        },

        savePost: function () {
            var me = this;

            var dataparams = {
                'id': this.id,
                'name': this.title,
                'description': this.body
            };
            console.log("Updating Post");
            this.$http.post("http://crossorigin.me/http://codepen.io/billmurrin/pen/EKXbyZ.js", dataparams, {
                xhr: {
                    onreadystatechange: function (response) {
                        if (this.readyState === 4) {
                            console.log("Updated Post");
                            console.log(response);
                            console.log(this.status);
                            console.log(this.response);
                            console.log("Sending Refresh Dispatch");
                            setTimeout(function() {
                                me.$dispatch('refreshReports')
                            }, 1500);
                            return;
                        }
                    }
                }
            });
            this.close();
        }
    },

    events: {
        edit_report: function (report) {
            this.id = report.id;
            this.title = report.name;
            this.body = report.description;
            this.show = true;
        }
    }
});

var demoData = [{
  "id": "ASWERDDD",
  "date_added": "2016-03-26",
  "length": "1",
  "name": "Test1",
  "description": "Description Test - Update"
}, {
  "id": "ASWERDAA",
  "date_added": "2016-03-24",
  "length": "1",
  "name": "Test1",
  "description": "Description Test 2 - Update"
}, {
  "id": "ASWERDBB",
  "date_added": "2016-03-25",
  "length": "1",
  "name": "Test1",
  "description": "Description Test 3 - Update"
}]

Vue.component('demo-grid', {
    template: '#grid-template',
    props: {
        list: [],
        columns: [],
        filterKey: String,
    },

    components: {
        'alerta': VueStrap.alert,
        'new-edit-modal': editModal
    },

    data: function () {
        var sortOrders = {};
        this.columns.forEach(function (key) {
            sortOrders[key] = 1
        });

        return {
            gdata: [],
            showRight: false,
            sortKey: '',
            sortOrders: sortOrders,
            showNewEditModal: false
        }
    },

    methods: {
        sortBy: function (key) {
            this.sortKey = key
            this.sortOrders[key] = this.sortOrders[key] * -1
        },

        deleterow: function (report) {
            var dataparams = {
                'id': report.id,
                '_token': "aaaabbbbbbccccccdddddddeeeeeeee"
            };

            this.$http.post("http://crossorigin.me/http://codepen.io/billmurrin/pen/EKXbyZ.js", dataparams,  {
                xhr: {
                    onreadystatechange: function (response) {
                        if (this.readyState === 4) {
                            console.log(this.status);
                            console.log(this.response);
                            return;
                        }
                    }
                }
            });

            alert("This ID would get deleted: " + report.id);
            console.log(report);
            this.gdata.$remove(report);
            this.showRight = !this.showRight;
        },

        editrow: function(report){
            this.$broadcast('edit_report', report);
            showNewEditModal = true
        }
    },

    events: {
        refreshReports: function () {
            var newdata = this;
            console.log("Refreshing reports.");
            this.$http.get("http://crossorigin.me/http://codepen.io/billmurrin/pen/EKXbyZ.js", {}, {
                xhr: {
                    onreadystatechange: function (response) {
                        if (this.readyState === 4) {
                            console.log(this.response);
                            console.log("refreshed");
                            console.log(newdata);
                            newdata.$set('gdata', JSON.parse(this.response));
                            return;
                        }
                    }
                }
            });
        }
    },

    created: function() {
        // Pushing the data to the data property so it's reactive
        this.gdata = this.list;
    },
});

// bootstrap the demo
var demo = new Vue({
    el: '#demo',

    data: {
        searchQuery: '',
        gridColumns: ['id', 'date_added', 'length', 'name', 'description'],
        gridData: demoData
    },
});
              
            
!
999px
What's a functional programmer's favorite animal? A lamb, duh!

Console