<!DOCTYPE html>
<html>
    <head>
    <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>
      
        <meta charset=utf-8 />
        <title>DataTables - JS Bin</title>
    </head>
    <body>
        <div class="container">
          <button>Reload</button>
          <select id="restaurants"></select>
            <table id="example" class="display" width="100%">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Start date</th>
                        <th>Salary</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Start date</th>
                        <th>Salary</th>
                    </tr>
                </tfoot>
            </table>
        </div>
    </body>
</html>
 
body {
    font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 0;
    color: #333;
    background-color: #fff;
}
div.container {
    min-width: 980px;
    margin: 0 auto;
}
 
$(document).ready(function() {
    var table = $('#example').DataTable( {
      "ajax": {
        url: "/ajax/objects.txt",
        dataSrc: function (data) {
          console.log('dataSrc');
          return data.data;
        }
        },
        "columns": [
            { "data": "name" },
          { "data": "position", name:  "position"},
          { "data": "office", name: "office" },
            { "data": "extn" },
            { "data": "start_date" },
            { "data": "salary" }
        ],
    initComplete: function(settings, json) {
        var columns = this.api().columns();
      this.api().column( 'position:name' ).data().sort().unique().each( function ( value ) {
            $("#restaurants").append( $('<option value="'+value+'">'+value+'</option>') );
        } );
    }
    } );
  
  var selectField = $('#restaurants');
  
  $('button').on('click', function () {
    table.ajax.reload(function ( json ) {
      console.log('ajax.reload');
    $("#restaurants").find('option').not(':first').remove();
    $("#restaurants").val("");
    //table.search( searchField.val() );
      //table.draw()
      
      table.column( 'office:name' ).data().sort().unique().each( function ( value ) {
               selectField.append( $('<option value="'+value+'">'+value+'</option>') );
    } );
    });
  });
  table.on( 'draw', function () {
    console.log( 'draw' );
} );
} );
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers