<!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>
    <link href="https://nightly.datatables.net/buttons/css/buttons.dataTables.css?_=c6b24f8a56e04fcee6105a02f4027462.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/buttons/js/dataTables.buttons.js?_=c6b24f8a56e04fcee6105a02f4027462"></script>
    <link href="https://nightly.datatables.net/select/css/select.dataTables.css?_=9a6592f8d74f8f520ff7b22342fa1183.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/select/js/dataTables.select.js?_=9a6592f8d74f8f520ff7b22342fa1183"></script>
    <link href="https://editor.datatables.net/extensions/Editor/css/editor.dataTables.min.css" rel="stylesheet" type="text/css" />
<script src="https://editor.datatables.net/extensions/Editor/js/dataTables.editor.min.js"></script>
    <link href="https://nightly.datatables.net/autofill/css/autoFill.dataTables.css?_=bc3763029fa6dfaf4c947ef25f079107.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/autofill/js/dataTables.autoFill.js?_=bc3763029fa6dfaf4c947ef25f079107"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
            <script src="https://cdn.datatables.net/plug-ins/1.10.19/dataRender/datetime.js"></script>
<link href="https://nightly.datatables.net/keytable/css/keyTable.dataTables.css?_=ad96c22f9d8971a682bb57b5b94f91ff.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/keytable/js/dataTables.keyTable.js?_=ad96c22f9d8971a682bb57b5b94f91ff"></script>
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
    <body>
    <div class="container">
      <table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn</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;
}
 
$(document).ready(function() {
  var data = [
    {
      "id": "1",
      "name": "Tiger Nixon",
      "position": "System Architect",
      "salary": "$320,800",
      "start_date": "2011/04/25",
      "office": "Edinburgh",
      "extn": 5421
    },
    {
      "id": "2",
      "name": "Garrett Winters",
      "position": "Accountant",
      "salary": "$170,750",
      "start_date": "2011/07/25",
      "office": "Tokyo",
      "extn": 8422
    },
    {
      "id": "3",
      "name": "Ashton Cox",
      "position": "Junior Technical Author",
      "salary": "$86,000",
      "start_date": "2009/01/12",
      "office": "San Francisco",
      "extn": 1562
    },
    {
      "id": "4",
      "name": "Cedric Kelly",
      "position": "Senior Javascript Developer",
      "salary": "$433,060",
      "start_date": "2012/03/29",
      "office": "Edinburgh",
      "extn": 6224
    },
    {
      "id": "5",
      "name": "Airi Satou",
      "position": "Accountant",
      "salary": "$162,700",
      "start_date": "2008/11/28",
      "office": "Tokyo",
      "extn": 5407
    },
    {
      "id": "6",
      "name": "Brielle Williamson",
      "position": "Integration Specialist",
      "salary": "$372,000",
      "start_date": "2012/12/02",
      "office": "New York",
      "extn": 4804
    },
    {
      "id": "7",
      "name": "Herrod Chandler",
      "position": "Sales Assistant",
      "salary": "$137,500",
      "start_date": "2012/08/06",
      "office": "San Francisco",
      "extn": 9608
    }
    ];
   
  //$.fn.dataTable.render.moment("M/D/YYYY");
  var editor = new $.fn.dataTable.Editor({
    table: "#example",
    idSrc: 'id',
    fields: [
            {
                label: 'Name:',
                name: 'name'
            },
            {
                label: 'Position:',
                name: 'position'
            },
            {
                label: 'Office:',
                name: 'office'
            },
            {
                label: 'Extn:',
                name: 'extn',
            },
            {
                label: 'Start date:',
                name: 'start_date',
                type: 'datetime',
                format: 'YYYY/M/D'
            },
            {
                label: 'Salary:',
                name: 'salary'
            }
    ]
  });
  var table = $("#example").DataTable({
    dom: 'Bf<"toolbar">rtip',
    data: data,
    rowId: 'id',
        keys: {
            columns: ':not(:first-child)',
            editor:  editor
        },
    columns: [
            { data: 'name' },
            { data: 'position' },
            { data: 'office' },
            { data: 'extn' },
            { data: 'start_date' },
            { data: 'salary' }
    ],
    select: true,
    buttons: [
      { extend: "create", editor: editor },
      { extend: "edit", editor: editor },
      { extend: "remove", editor: editor }
    ],
    "initComplete": function(settings, json) {
        $('div.toolbar').html('<table><tr><td> Lærer: </td><td align="center"><input type="text" id="laerer_filter"></td><td> Hold: </td><td align="center"><input type="text" id="hold_filter"></td></tr></table>');
        
        $('#laerer_filter, #hold_filter').on('focus', function () {
          table.cell.blur();
        } ); 
      
      
        $('#laerer_filter').on( 'keyup change', function () {//filtrerer lærer
        $('#example').DataTable().column( 5 ).search(
        $('#laerer_filter').val()
        ).draw();
        //table.cell.blur();//modvirker at indtastning kommer i tal celle - fra Allan
        } );
 
        $('#hold_filter').on( 'keyup change', function () {//filtrerer hold
        $('#example').DataTable().column( 6 ).search(
        $('#hold_filter').val()
        ).draw();
        //table.cell.blur();//modvirker at indtastning kommer i tal celle - fra Allan
        } );
    }
  });
  table.cell.blur();//modvirker at indtastning kommer i tal celle - fra Allan
  
  $('#example').on('click', 'tbody tr td', function() {
    editor.inline(this);
  }); 
  
  $('button').on('click', function () {
    console.log(table.column(3).data().toArray());
  });
});
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers