2016-02-19 66 views
0

如何增加我的ID以便我可以在所有表​​中生成數據表?我不太瞭解如何循環數據表功能。它甚至有可能嗎?我不知道這個插件是如何工作的,因爲我從來沒有在一個循環數據表遞增

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 
    <script src="http://localhost/IM_Project/facefiles/jquery-1.2.2.pack.js" type="text/javascript"></script> 
    <link href="http://localhost/IM_Project/facefiles/facebox.css" media="screen" rel="stylesheet" type="text/css" /> 
    <script src="http://localhost/IM_Project/facefiles/facebox.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
     jQuery(document).ready(function($) { 
      $('a[rel*=facebox]').facebox() 
     }) 
    </script> 


    <script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script> 

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
    <script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script> 

<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css"> 
<br> 
<br> 
<br> 
<br> 

<div class="panel panel-default"> 
    <div class="panel-heading"> 
    <h1 class="panel-title"><center><span class="glyphicon glyphicon-list"></span>   Your Students</h1></center> 
    </div> 

<div style="padding-top:50px;" class="container" id="in-body"> 
     <div class="row"> 

     <div class="panel-body"> 


    <?php $example='0'; 
    foreach($instruct_course as $data1){ 
     if($data1->IdNum==$this->session->userdata('Idnum')&&$data1->flag=='1'){ $example++;?>  

      <div class="panel panel-info"> 
      <div class="panel-heading"> 
       <h3 class="panel-title"> <?php echo ($data1->course_id); ?> &nbsp; 
    <?php if ($data1->course_id!=NULL) { 
      foreach($course as $data2){ 
     if ($data2->courseID==$data1->course_id&&$data2->flag=='1') { 
      echo ($data2->CourseName); 

      }  

       } 
     } ?> </h3> 
      </div> 
      <div class="panel-body"> 
       <div class="row" style="padding: 0 20px 0 20px;"> 

       <table class="table table-hover" id='<?php echo ($example); ?>'> 
        <thead> 
        <tr> 
         <th style="width: 35%;">Username</th> 
         <th>Email</th> 
         <th>Family name</th> 
         <th>Details</th> 

        </tr> 
        </thead> 
        <tbody> 
<?php 
    foreach($user_course as $data3){ 
     if($data3->flag=='1'){ 
foreach($user as $data4){    
if ($data4->flag!='2'&&($data3->Email)==($data4->Email)&&($data1->course_id)==($data3->course_id)) { 
        ?> 


        <tr> 
         <td><?php echo ($data4->username); ?></td> 
         <td><?php echo ($data4->Email); ?></td> 
         <td><?php echo ($data4->Fname); ?></td> 
         <td><button type="button" class="btn btn-info btn-sm" data-backdrop="false" data-show="true" data-toggle="modal" data-target="#myModal">Demo Modal</button></td> 
        </tr> 




        <?php } 
        } 
       } 
        }?> 
        </tbody> 
       </table> 



       <div class=" col-md-9 col-lg-9 "> 



       </div> 
       </div> 
      </div> 

<script type="text/javascript"> 
$(document).ready(function() { 
    $('# (echo ($example);)').DataTable(); 
}); 

</script> 

      </div> 
<?php } 


} 

?> 




<!-- Modal --> 
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
    <div class="modal-dialog" role="document"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
     <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
     </div> 
     <div class="modal-body"> 
     ... 
     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
     <button type="button" class="btn btn-primary">Save changes</button> 
     </div> 
    </div> 
    </div> 
</div> 


     </div> 
     </div> 
    </div> 
    </div> 
+0

你能嘗試以另一種方式解釋這個嗎? 「如何增加我的ID以便我可以在所有表​​中生成數據表?我不太瞭解如何循環數據表功能。」 – jonmrich

+0

當您將數據表分配給帶有ID權限的表時,DataTable工作正常嗎? 我想使ID增量,以便每個產生的表將有我認爲我理解的DataTables –

+0

。您需要爲每個表格單獨啓動。據我所知,沒有辦法「循環」數據表。增加表的ID並將它們添加到'div'中是相當容易的,可以用jQuery來完成,你可以得到你添加的表的數量,但是你需要爲每個數據表創建JS。這有點棘手,但仍然可以使用JavaScript/jQuery。 – jonmrich

回答

0

您可以使用一個類中遇到的數據表,然後初始化與該類數據表。您已指定類table

<table class="table table-hover"></table> 

所以,你的初始化將是:

$(document).ready(function() { 
    $('.table').DataTable(); 
}); 

任何表與類table將與數據表呈現。