cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div id="tabledemo">
  <h3>Vue Datatable example</h3>
  Filter by anything: <input v-model="search">
  <hr>
  <data-table :users="filteredUsers"></data-table>
</div>
            
          
!
            
              Vue.component('data-table', {
  template: '<table></table>',
  props: ['users'],
  data() {
    return {
      headers: [
        { title: 'ID' },
        { title: 'Username', class: 'some-special-class' },
        { title: 'Real Name' },
        { title: 'Phone' },
        { title: 'Email' },
        { title: 'Website' }
      ],
      rows: [] ,
      dtHandle: null
    }
  },
  watch: {
    users(val, oldVal) {
      let vm = this;
      vm.rows = [];
      // You should _probably_ check that this is changed data... but we'll skip that for this example.
      val.forEach(function (item) {
        // Fish out the specific column data for each item in your data set and push it to the appropriate place.
        // Basically we're just building a multi-dimensional array here. If the data is _already_ in the right format you could
        // skip this loop...
        let row = [];

        row.push(item.id);
        row.push(item.username);
        row.push(item.name);
        row.push(item.phone);
        row.push('<a href="mailto://' + item.email + '">' + item.email + '</a>');
        row.push('<a href="http://' + item.website + '" target="_blank">' + item.website + '</a>');

        vm.rows.push(row);
      });

      // Here's the magic to keeping the DataTable in sync.
      // It must be cleared, new rows added, then redrawn!
      vm.dtHandle.clear();
      vm.dtHandle.rows.add(vm.rows);
      vm.dtHandle.draw();
    }
  },
  ready() {
    let vm = this;
    // Instantiate the datatable and store the reference to the instance in our dtHandle element.
    vm.dtHandle = $(this.$el).DataTable({
      // Specify whatever options you want, at a minimum these:
      columns: vm.headers,
      data: vm.rows,
      searching: false,
      paging: false,
      info: false
    });
  }  
});

new Vue({
  el: '#tabledemo',
  data: {
    users: [],
    search: ''
  },
  computed: {
    filteredUsers() {
      let users = this.users;
      return this.$options.filters.filterBy(users, this.search);
    }
  },
  ready() {
    let vm = this;
    $.ajax({
      url: 'https://jsonplaceholder.typicode.com/users',
      success(res) {
        vm.users = res;
      }
    });
  }
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console