Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
  <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
</head>
<body id="app">
  <button id="add-column">
    Add column
  </button>
  <table class="data-table"/>
</body>
</html>
 
const app = {
  $: $('#app'),
  columns : [],
  data: [],
  table: null,
  addColumn() {
    this.columns = [
      ...this.columns,
      {
        title: "Column"
      },
    ]
    this.render()
  },
  render() {
    if (this.table) {
      this.table.destroy()
    }
    
    this.table = this.$.find('.data-table')
    .empty()
    .DataTable({
      columns: this.columns,
      data: this.data,
    })
  }
}
$('#add-column').click(() => {
  app.addColumn()
})
app.addColumn()
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers