2016-07-20 9 views
0

Ich versuche, das Datatables jquery-Plugin mit meiner HTML-Tabelle zu implementieren, aber kein Glück. Ich verlinke das Datatables-CDN sowohl für das CSS-Styling als auch für das Datatables-Skript selbst und verlinke mit dem gehosteten jquery-Plugin von Google. Ich habe auch eine lokale Javascript-Datei mit dem Skript, um Datentabellen auf meinem Tisch zu initialisieren. Ich gehe, um die HTML-Seite zu öffnen und meine einfache Tabelle zu bekommen, als ob DataTable nicht einmal funktioniert. Was könnte ich falsch machen?DataTables jquery plugin funktioniert nicht, eine leere Seite bekommen?

<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css"/> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
<script type="text/javascript" src="http://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="datatables.js"></script> 

<table id="mytable"> 
<table> 
    <thead> 
    <tr> 
     <th>High-Level Category</th> 
     <th>Device Type</th> 
     <th>Hostname</th> 
     <th>IP Address</th> 
     <th>Owner</th> 
     <th>Organizational Unit</th> 
     <th>Organizational Unit Email</th> 
     <th>Universal Forwarder or Syslog?</th> 
     <th>In PCI?</th> 
     <th>Notes</th> 
    </tr> 
    </thead> 
<tbody contenteditable> 
    <tr> 
     <td contenteditable="true">SECDEV1</td> 
     <td contenteditable="true">Firewall</td> 
     <td contenteditable="true">Description 1</td> 
     <td contenteditable="true">1.1.1.1</td> 
     <td contenteditable="true">Kim</td> 
     <td contenteditable="true">Information Technology</td> 
     <td contenteditable="true">[email protected]</td> 
     <td contenteditable="true">Syslog</td> 
     <td contenteditable="true">Yes</td> 
     <td contenteditable="true">notes</td> 
    </tr> 
    <tr> 
     <td contenteditable="true">SECDEV2</td> 
     <td contenteditable="true">Switch</td> 
     <td contenteditable="true">description2</td> 
     <td contenteditable="true">2.2.2.2</td> 
     <td contenteditable="true">Bob</td> 
     <td contenteditable="true">Information Networking</td> 
     <td contenteditable="true">[email protected]</td> 
     <td contenteditable="true">Syslog</td> 
     <td contenteditable="true">NO</td> 
     <td contenteditable="true">more notes</td> 
    </tr> 
</tbody> 

Die lokale js Datei ich habe, ist wie folgt:

$(document).ready(function(){ 

    $('#mytable').dataTable(); 

}); 

Jede Hilfe wäre toll.

Danke!

+0

Warum beide datatables.js und Datatable min.js. entferne datatables.js. – Ranjan

+0

Die Datei "datatables.js" ist mein lokales JavaScript-Skript, das DataTables initialisiert. Ist das was Datatables.min.js von Datatables CDN tut? – Zach

+0

beide sind gleich, aber min.js ist eine verkleinerte Version. entfernen Sie es einfach und überprüfen Sie es. – Ranjan

Antwort

1

Ihr HTML-Code ist falsch. Es gab eine extra offene Ende Tabelle Tag. Ich korrigierte Ihre HTML unter:

<table id="mytable"> 
     <thead> 
     <tr> 
      <th>High-Level Category</th> 
      <th>Device Type</th> 
      <th>Hostname</th> 
      <th>IP Address</th> 
      <th>Owner</th> 
      <th>Organizational Unit</th> 
      <th>Organizational Unit Email</th> 
      <th>Universal Forwarder or Syslog?</th> 
      <th>In PCI?</th> 
      <th>Notes</th> 
     </tr> 
     </thead> 
     <tbody contenteditable> 
      <tr> 
       <td contenteditable="true">SECDEV1</td> 
       <td contenteditable="true">Firewall</td> 
       <td contenteditable="true">Description 1</td> 
       <td contenteditable="true">1.1.1.1</td> 
       <td contenteditable="true">Kim</td> 
       <td contenteditable="true">Information Technology</td> 
       <td contenteditable="true">[email protected]</td> 
       <td contenteditable="true">Syslog</td> 
       <td contenteditable="true">Yes</td> 
       <td contenteditable="true">notes</td> 
      </tr> 
      <tr> 
       <td contenteditable="true">SECDEV2</td> 
       <td contenteditable="true">Switch</td> 
       <td contenteditable="true">description2</td> 
       <td contenteditable="true">2.2.2.2</td> 
       <td contenteditable="true">Bob</td> 
       <td contenteditable="true">Information Networking</td> 
       <td contenteditable="true">[email protected]</td> 
       <td contenteditable="true">Syslog</td> 
       <td contenteditable="true">NO</td> 
       <td contenteditable="true">more notes</td> 
      </tr> 
     </tbody> 
    </table> 
1

Um Ihre erwartete Ergebnis zu erzielen, verwenden Sie unter CDN Bibliotheken

<!-- DataTables CSS --> 
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css"> 

<!-- jQuery --> 
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script> 

<!-- DataTables --> 
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script> 

Codepen- http://codepen.io/nagasai/pen/AXyLXO

+0

@zach, wenn meine Antwort Ihrer Frage geholfen hat, markieren Sie sie bitte als beantwortet :) –

Verwandte Themen