Datatables console error jQuery.Deferred exception: Cannot set property '_DT_CellIndex'

datatables kok gak work ya, dapet console error

 jQuery.Deferred exception: Cannot set property '_DT_CellIndex'

ini isi codingannya

<?php
  include("config.php");
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- bootstrap css -->
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="css/style.css">

  <!-- icons -->
  <link rel="apple-touch-icon" sizes="180x180" href="icons/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="icons/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="icons/favicon-16x16.png">
  <link rel="manifest" href="icons/site.webmanifest">
  <link rel="mask-icon" href="icons/safari-pinned-tab.svg" color="#5bbad5">
  <meta name="msapplication-TileColor" content="#da532c">
  <meta name="theme-color" content="#ffffff">
  <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
  <script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>

  <title>INKA</title>
</head>
<body >
    <!-- php func -->
    <?php
      session_start();

      if($_SESSION['id']=='$id'){
        header("location:index.php?pesan=gagal");
      }
    ?>
    <!--  -->

    <!-- jumbo tron  -->
    <div class="jumbotron jumbotron-fluid ">
      <!-- container -->
      <div class="container mt-n4" style="height:500px">
        <!-- flexbox -->
        <div class=" d-flex flex-row-reverse mb-3 ml-5">
        <a href="logout.php" type="button" class="btn btn-danger mb-5" id="keluar" name="keluar ">keluar</a>
        </div>
        <!--flexbox end -->

        <!-- card -->
        <div class="card text-nowrap">
          <div class="card-header text-center strong">
          <!-- tampil nama -->
          <?php
          $query = "SELECT * FROM user
                    where id= $_SESSION[id]";

          $query = "SELECT id,nama
                    FROM user
                    where user.id= $_SESSION[id]";

          $result = mysqli_query($koneksi, $query);

          if(!$result){
            die ("Query Error: ".mysqli_errno($koneksi).
            " - ".mysqli_error($koneksi));
          }
          while($data = mysqli_fetch_assoc($result))
          {
          echo "<h3 class='text-uppercase'>HASIL KINERJA </br> <p class='font-weight-bold text-danger'> $data[nama] </p> </h3>";
          }
          ?>
          <!-- tampil nama end -->
          </div>
          <div class="card-body">
            <!-- <form class="form-inline my-2 my-lg-0 pt-2 pb-2">
              <input class="form-control mr-sm-2" type="search" placeholder="Filter tanggal" aria-label="Search" id="myInput" onkeyup="myFunction()" >
            </form> -->
            <!-- table -->
            <div >
            <div class="table-responsive table-fixed table-wrapper">
              <table class="table table-bordered table-striped table-fixed text-center" id="myTable">
                <thead>
                  <tr>
                    <th scope="col">No</th>
                    <th scope="col">ID</th>
                    <th scope="col">Nama</th>
                    <th scope="col">Golongan</th>
                    <th scope="col">Nilai Output</th>
                    <th scope="col">Penilaian Atasan</th>
                    <th scope="col">Nilai Learning</th>
                    <th scope="col">Nilai Kedisiplinan</th>
                    <th scope="col">Nilai 5R</th>
                    <th scope="col">Hasil</th>
                    <th scope="col">Tanggal</th>
                  </tr>
                </thead>
                  <!-- query -->
                  <?php
                  $no = 0;
                  $query = "SELECT * FROM user
                            where id= $_SESSION[id]";

                  $query = "SELECT user.id,user.nama,golongan,nilai_output,nilai_atasan,nilai_learning,nilai_kedisiplinan,nilai_5r,overall,tanggal
                            FROM tkaryawan
                            JOIN user
                            ON user.id=tkaryawan.id
                            where user.id= $_SESSION[id]
                            ORDER BY tanggal DESC";

                  $result = mysqli_query($koneksi, $query);

                  if(!$result){
                    die ("Query Error: ".mysqli_errno($koneksi).
                    " - ".mysqli_error($koneksi));
                  }
                  while($data = mysqli_fetch_assoc($result))
                  {
                    $no++;
                    ?>
                  <tbody>
                    <tr>
                      <th scope="row"><?php echo $no; ?></th>
                      <td><?php echo $data['id'];?></td>
                      <td class="text-capitalize"><?php echo $data['nama'];?></td>
                      <td><?php echo $data['golongan'];?></td>
                      <td><?php echo $data['nilai_output'];?></td>
                      <td><?php echo $data['nilai_atasan'];?></td>
                      <td><?php echo $data['nilai_learning'];?></td>
                      <td><?php echo $data['nilai_kedisiplinan'];?></td>
                      <td><?php echo $data['nilai_5r'];?></td>
                      <td class="font-weight-bold text-danger"><?php echo $data['overall'];?></td>
                      <td class="text-secondary"><?php echo $data['tanggal'];?></td>
                    <tr>
                  <tbody>
                  <?php
                  }

                  mysqli_free_result($result);

                  mysqli_close($koneksi);
                  ?>
              </table>
            </div>
            <!-- table end -->
          </div>
        </div>
        <!-- card end -->

      </div>
      <!-- container end -->
    </div>
    <!-- jumbotron end -->

  <!-- script -->
  <script src="js/custom.js"></script>
  <script src="js/bootstrap.min.js"></script>
  <script>
    $(document).ready(function(){
        $('#myTable').DataTable();
    });
</script>


</body>
</html>
avatar bagaskurniawan_google
@bagaskurniawan_google

1 Kontribusi 0 Poin

Diperbarui 4 tahun yang lalu

1 Jawaban:

<div>Hallo, izin menjawab, sepertinya looping agan, membuat struktur tabelnya jadi tidak beraturan.<br>Untuk membuat tabel dengan terstruktur harusnya sepert ini :<br><br></div><pre>&lt;table border = "1" width = "100%"&gt; &lt;!-- Mendefinisikan header table --&gt; &lt;thead&gt; &lt;tr&gt; &lt;td colspan = "4"&gt;This is the head of the table&lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt;

&amp;lt;!-- Mendefinisikan body table --&amp;gt;
&amp;lt;tbody&amp;gt;
	&amp;lt;tr&amp;gt;
		&amp;lt;td&amp;gt;Cell 1&amp;lt;/td&amp;gt;
		&amp;lt;td&amp;gt;Cell 2&amp;lt;/td&amp;gt;
		&amp;lt;td&amp;gt;Cell 3&amp;lt;/td&amp;gt;
		&amp;lt;td&amp;gt;Cell 4&amp;lt;/td&amp;gt;
	&amp;lt;/tr&amp;gt;
&amp;lt;/tbody&amp;gt;
&amp;lt;!-- Mendefinisikan footer pada table --&amp;gt;
&amp;lt;tfoot&amp;gt;
	&amp;lt;tr&amp;gt;
		&amp;lt;td colspan = &quot;4&quot;&amp;gt;This is the foot of the table&amp;lt;/td&amp;gt;
	&amp;lt;/tr&amp;gt;
&amp;lt;/tfoot&amp;gt;

&lt;/table&gt;</pre><div><br>plugin Datatable, mengharuskan struktur tabel kita seperti diatas, sedangkan dari script agan, agan melakukan looping pada tag &lt;tbody&gt; sehingga tag tersebut akan berulang beberapa kali. Solusinya, lakukan looping (while) di&nbsp; dalam &lt;tbody&gt;, jadi yang di loop itu tag &lt;tr&gt; -nya, kodenya seperti ini :<br><br></div><pre>&lt;?php include("config.php"); ?&gt;

&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;

<em>&lt;!-- bootstrap css --&gt;</em> &lt;link rel="stylesheet" href="css/bootstrap.min.css"&gt; &lt;link rel="stylesheet" href="css/style.css"&gt;

<em>&lt;!-- icons --&gt;</em> &lt;link rel="apple-touch-icon" sizes="180x180" href="icons/apple-touch-icon.png"&gt; &lt;link rel="icon" type="image/png" sizes="32x32" href="icons/favicon-32x32.png"&gt; &lt;link rel="icon" type="image/png" sizes="16x16" href="icons/favicon-16x16.png"&gt; &lt;link rel="manifest" href="icons/site.webmanifest"&gt; &lt;link rel="mask-icon" href="icons/safari-pinned-tab.svg" color="#5bbad5"&gt; &lt;meta name="msapplication-TileColor" content="#da532c"&gt; &lt;meta name="theme-color" content="#ffffff"&gt; &lt;script src="https://code.jquery.com/jquery-3.1.0.js"&gt;&lt;/script&gt; &lt;script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"&gt;&lt;/script&gt;

&lt;title&gt;INKA&lt;/title&gt; &lt;/head&gt; &lt;body &gt; <em>&lt;!-- php func --&gt;</em> &lt;?php session_start();

  if($_SESSION[&#039;id&#039;]==&#039;$id&#039;){
    header(&quot;location:index.php?pesan=gagal&quot;);
  }
?&amp;gt;
&lt;em&gt;&amp;lt;!--  --&amp;gt;&lt;/em&gt;

&lt;em&gt;&amp;lt;!-- jumbo tron  --&amp;gt;&lt;/em&gt;
&amp;lt;div class=&quot;jumbotron jumbotron-fluid &quot;&amp;gt;
  &lt;em&gt;&amp;lt;!-- container --&amp;gt;&lt;/em&gt;
  &amp;lt;div class=&quot;container mt-n4&quot; style=&quot;height:500px&quot;&amp;gt;
    &lt;em&gt;&amp;lt;!-- flexbox --&amp;gt;&lt;/em&gt;
    &amp;lt;div class=&quot; d-flex flex-row-reverse mb-3 ml-5&quot;&amp;gt;
    &amp;lt;a href=&quot;logout.php&quot; type=&quot;button&quot; class=&quot;btn btn-danger mb-5&quot; id=&quot;keluar&quot; name=&quot;keluar &quot;&amp;gt;keluar&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    &lt;em&gt;&amp;lt;!--flexbox end --&amp;gt;&lt;/em&gt;

    &lt;em&gt;&amp;lt;!-- card --&amp;gt;&lt;/em&gt;
    &amp;lt;div class=&quot;card text-nowrap&quot;&amp;gt;
      &amp;lt;div class=&quot;card-header text-center strong&quot;&amp;gt;
      &lt;em&gt;&amp;lt;!-- tampil nama --&amp;gt;&lt;/em&gt;
      &amp;lt;?php
      $query = &quot;SELECT * FROM user 
                where id= $_SESSION[id]&quot;;

      $query = &quot;SELECT id,nama 
                FROM user
                where user.id= $_SESSION[id]&quot;;

      $result = mysqli_query($koneksi, $query);

      if(!$result){
        die (&quot;Query Error: &quot;.mysqli_errno($koneksi).
        &quot; - &quot;.mysqli_error($koneksi));
      }
      while($data = mysqli_fetch_assoc($result))
      {
      echo &quot;&amp;lt;h3 class=&#039;text-uppercase&#039;&amp;gt;HASIL KINERJA &amp;lt;/br&amp;gt; &amp;lt;p class=&#039;font-weight-bold text-danger&#039;&amp;gt; $data[nama] &amp;lt;/p&amp;gt; &amp;lt;/h3&amp;gt;&quot;;
      }
      ?&amp;gt;
      &lt;em&gt;&amp;lt;!-- tampil nama end --&amp;gt;&lt;/em&gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class=&quot;card-body&quot;&amp;gt;
        &lt;em&gt;&amp;lt;!-- &amp;lt;form class=&quot;form-inline my-2 my-lg-0 pt-2 pb-2&quot;&amp;gt;&lt;/em&gt;

<em> &lt;input class="form-control mr-sm-2" type="search" placeholder="Filter tanggal" aria-label="Search" id="myInput" onkeyup="myFunction()" &gt;</em> <em> &lt;/form&gt; --&gt;</em> <em>&lt;!-- table --&gt;</em> &lt;div &gt; &lt;div class="table-responsive table-fixed table-wrapper"&gt; &lt;table class="table table-bordered table-striped table-fixed text-center" id="myTable"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope="col"&gt;No&lt;/th&gt; &lt;th scope="col"&gt;ID&lt;/th&gt; &lt;th scope="col"&gt;Nama&lt;/th&gt; &lt;th scope="col"&gt;Golongan&lt;/th&gt; &lt;th scope="col"&gt;Nilai Output&lt;/th&gt; &lt;th scope="col"&gt;Penilaian Atasan&lt;/th&gt; &lt;th scope="col"&gt;Nilai Learning&lt;/th&gt; &lt;th scope="col"&gt;Nilai Kedisiplinan&lt;/th&gt; &lt;th scope="col"&gt;Nilai 5R&lt;/th&gt; &lt;th scope="col"&gt;Hasil&lt;/th&gt; &lt;th scope="col"&gt;Tanggal&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; <em>&lt;!-- query --&gt;</em> &lt;?php $no = 0; $query = "SELECT * FROM user where id= $_SESSION[id]";

              $query = &quot;SELECT user.id,user.nama,golongan,nilai_output,nilai_atasan,nilai_learning,nilai_kedisiplinan,nilai_5r,overall,tanggal 
                        FROM tkaryawan 
                        JOIN user 
                        ON user.id=tkaryawan.id 
                        where user.id= $_SESSION[id] 
                        ORDER BY tanggal DESC&quot;;

              $result = mysqli_query($koneksi, $query);
              
              if(!$result){
                die (&quot;Query Error: &quot;.mysqli_errno($koneksi).
                &quot; - &quot;.mysqli_error($koneksi));
              }
              while($data = mysqli_fetch_assoc($result))
              {
                $no++;
                ?&amp;gt;

                &amp;lt;tr&amp;gt;
                  &amp;lt;th scope=&quot;row&quot;&amp;gt;&amp;lt;?php echo $no; ?&amp;gt;&amp;lt;/th&amp;gt;
                  &amp;lt;td&amp;gt;&amp;lt;?php echo $data[&#039;id&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                  &amp;lt;td class=&quot;text-capitalize&quot;&amp;gt;&amp;lt;?php echo $data[&#039;nama&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                  &amp;lt;td&amp;gt;&amp;lt;?php echo $data[&#039;golongan&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                  &amp;lt;td&amp;gt;&amp;lt;?php echo $data[&#039;nilai_output&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                  &amp;lt;td&amp;gt;&amp;lt;?php echo $data[&#039;nilai_atasan&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                  &amp;lt;td&amp;gt;&amp;lt;?php echo $data[&#039;nilai_learning&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                  &amp;lt;td&amp;gt;&amp;lt;?php echo $data[&#039;nilai_kedisiplinan&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                  &amp;lt;td&amp;gt;&amp;lt;?php echo $data[&#039;nilai_5r&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                  &amp;lt;td class=&quot;font-weight-bold text-danger&quot;&amp;gt;&amp;lt;?php echo $data[&#039;overall&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                  &amp;lt;td class=&quot;text-secondary&quot;&amp;gt;&amp;lt;?php echo $data[&#039;tanggal&#039;];?&amp;gt;&amp;lt;/td&amp;gt;
                &amp;lt;tr&amp;gt;
              &amp;lt;?php
              }

              mysqli_free_result($result);

              mysqli_close($koneksi);
              ?&amp;gt;
            &amp;lt;tbody&amp;gt;
          &amp;lt;/table&amp;gt;
        &amp;lt;/div&amp;gt;
        &lt;em&gt;&amp;lt;!-- table end --&amp;gt;&lt;/em&gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &lt;em&gt;&amp;lt;!-- card end --&amp;gt;&lt;/em&gt;

  &amp;lt;/div&amp;gt;
  &lt;em&gt;&amp;lt;!-- container end --&amp;gt;&lt;/em&gt;
&amp;lt;/div&amp;gt;
&lt;em&gt;&amp;lt;!-- jumbotron end --&amp;gt;&lt;/em&gt;

<em>&lt;!-- script --&gt;</em> &lt;script src="js/custom.js"&gt;&lt;/script&gt; &lt;script src="js/bootstrap.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(){ $('#myTable').DataTable(); }); &lt;/script&gt;

&lt;/body&gt; &lt;/html&gt;</pre><div><br>Semoga membantu!</div>

avatar ahanafi
@ahanafi

815 Kontribusi 554 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban