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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <div id="app">
  <data-grid
    url="https://api.mockaroo.com/api/b5f38710?count=8&key=cdbbbcd0"
    :columns="{id: 'ID', nick: 'Nick name', first: 'First name', last: 'Last name'}"
  ></data-grid>
  <data-grid
    url="https://api.mockaroo.com/api/03f2c610?count=8&key=cdbbbcd0"
    :columns="{id: 'ID', first: 'First name', last: 'Last name', email: 'Email'}"
  ></data-grid>
</div>

<template id="data-grid">
  <transition
    appear
    v-on:before-appear="onCreate"
    v-on:appear="onData"
  >
    <div class="data-grid">
      <div class="tools"> 
        <div class="search">
          <input
            type="text"
            @input="updateQuery"
            :value="query"
            placehorder="search..."
          >
          <button class="clear" @click="clearQuery">clear</button>
        </div>
      </div>
      <div class="table">
        <div class="thead" @click="sortUsers">
          <div class="tr">
            <span v-for="(col, key) in columns" class="td" :data-key=key>
              {{ col }}
              <span
                v-if="prevKey === key"
                :class="['arrow', orderDesc ? 'desc' : 'asc']">
              </span>
            </span>
          </div>
        </div>
        <transition-group name="users" tag="div" class="tbody">
          <div class="tr" v-for="row in filteredUsers" :key="row.id">
            <span class="td" v-for="column in row">{{ column }}</span>
          </div>
        </transition-group>
      </div>
    </div>
  </transition>
</template>
              
            
!

CSS

              
                .data-grid {
  width: 98%;
  margin: 10px auto;
  padding: 2px;
  background-color: white;
  border: 2px solid #3F51B5;
  overflow: hidden;
}
.table {
  display: table;
  width: 100%;
  font-size: 13px;
  font-family: Arial, sans-serif;
  color: #263238;
  cursor: pointer;
}
.thead {
  display: table-header-group;
}
.tbody {
  display: table-row-group;
}
.tr {
  display: table-row;
}
.td {
  display: table-cell;
  position: relative;
}
.tr .td:not(:last-child) {
  border-right: 2px solid white;
}
.thead .td {
  padding: 5px 14px;
  background-color: #3F51B5;
  color: white;
  font-weight: bold;
  text-align: center;
}
.tbody .td {
  padding: 4px;
  color: #263238;
  text-align: center;
}
.tbody .tr:hover .td {
  background-color: #C5CAE9;
}
.tbody .tr:hover .td:not(:last-child) {
  border-right: 2px solid #C5CAE9;
}
.tools {
  margin: 10px;
  box-sizing: border-box;
}
.tools:after {
  content: "";
  display: block;
  clear: both;
}
.search {
  float: right;
}
.arrow {
  display: inline-block;
  position: absolute;
  width: 0;
  height: 0;
  margin-left: 5px;
  margin-top: 5px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  transition: all .6s;
}
.asc {
  border-bottom: 6px solid white;
}
.desc {
  border-top: 6px solid white;
}
.users-move {
  transition: transform .6s;
}
.users-enter-active, .users-leave-active {
  transition: all .6s;
}
.users-enter, .users-leave-to {
  opacity: 0;
  transform: translateY(30px);
}
              
            
!

JS

              
                Vue.component('data-grid', {
  template: '#data-grid',
  props: ['url', 'columns'],
  data () {
    return {
      users: [],
      query: '',
      prevKey: 'id',
      orderDesc: false
    }
  },
  computed: {
    filteredUsers () {
      return _.filter(this.users, user =>
        _.find(user, prop =>
          new RegExp(this.query, 'i').test(prop)
        )
      )
    }
  },
  methods: {
    sortUsers (evt) {
      var key = evt.target.dataset.key
      if (this.prevKey === key) {
        this.users.reverse()
        this.orderDesc = !this.orderDesc
      } else {
        this.users = _.sortBy(this.users, key)
        this.orderDesc = false
        this.prevKey = key
      }
    },
    updateQuery: _.debounce(function (evt) {
      this.query = evt.target.value
    }, 300),
    clearQuery () {
      this.query = ''
    },
    onCreate (elm) {
      elm.style.opacity = 0
    },
    async onData (elm) {
      this.users = await axios
        .get(this.url)
        .then(res => res.data)
      Velocity(elm, "fadeIn", {duration: 600})
    } 
  }
})

new Vue({
  el: '#app'
})
              
            
!
999px

Console