Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html lang="en">
- <head>
- <!-- <style type="text/css">@charset "UTF-8";</style> -->
- <meta charset="utf-8">
- <link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" >
- <link rel="stylesheet" href="https://cdn.datatables.net/keytable/2.3.2/css/keyTable.jqueryui.min.css" >
- <link rel="stylesheet" href="https://cdn.datatables.net/fixedcolumns/3.2.4/css/fixedColumns.dataTables.min.css" >
- <link rel="stylesheet" href="https://cdn.datatables.net/fixedheader/3.1.3/css/fixedHeader.dataTables.min.css" >
- <link rel="stylesheet" href="https://cdn.datatables.net/select/1.2.4/css/select.dataTables.min.css" >
- <title>Ketura's PC</title>
- </head>
- <body id="">
- <div id="app">
- <div class="w100">
- <div class="dash-panel-box" width="80%">
- <div class="dash-heading row">
- <input id="new-type-input">
- <button name="data-report" type="button" class="btn btn-dark">Add Row</button>
- <button name="btnDestroy" type="button" class="btn btn-dark">Destroy DataTable</button>
- </div>
- <table id="type-table" class="display cell-border compact hover stripe" width="80%" cellspacing="0"> </table>
- </div>
- </div>
- </div>
- <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/css/jquery.dataTables.css" /> -->
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.js"></script>
- <script src="https://cdn.datatables.net/fixedcolumns/3.2.4/js/dataTables.fixedColumns.min.js"></script>
- <script src="https://cdn.datatables.net/fixedheader/3.1.3/js/dataTables.fixedHeader.min.js"></script>
- <script src="https://cdn.datatables.net/select/1.2.4/js/dataTables.select.min.js"></script>
- <script>
- var pokeTypes = ['Fire', 'Water', 'Electric'];
- //The jQuery(callback) function is basically something which runs after the entire document has been loaded.
- jQuery(function () {
- var typeDatatable = RegenerateTypeTable(true);
- jQuery('[name=data-report]').on('click', function () {
- //console.log(typeDatatable.data());
- pokeTypes.push($('#new-type-input').val());
- //typeDatatable.destroy();
- typeDatatable = RegenerateTypeTable(true);
- //console.log(typeDatatable.data());
- });
- jQuery('[name=btnDestroy]').on('click', function () {
- typeDatatable.destroy();
- });
- });
- function RegenerateTypeTable(debug)
- {
- console.log(pokeTypes);
- var tableData = [];
- var headerRow = {name:""};
- var columns = [
- { data: 'name', className: 'dt-center'}
- ];
- pokeTypes.forEach(function(row){
- headerRow[row] = row;
- });
- tableData.push(headerRow);
- pokeTypes.forEach(function(row){
- columns.push({ data: row, className: 'dt-center'});
- var dataRow = {name: row};
- pokeTypes.forEach(function(col){
- dataRow[col] = 0;
- });
- tableData.push(dataRow);
- });
- console.log(tableData);
- console.log(columns);
- if(debug)
- {
- var typeDatatable = jQuery("#type-table").DataTable({
- "data": tableData,
- "autoWidth": true,
- "columns": columns,
- paging: false,
- ordering: false,
- searching: false,
- info: false,
- processing: true
- });
- }
- return typeDatatable
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment