2016-11-30 67 views
2

我列出的所有用户在我看来,像工作如下:数据表不在Laravel 5.3

class UsersController extends Controller 
{ 
    public function index(){ 
     $user = User::orderBy('id', 'DESC')->get(); 
     return view('admin.users.index',['users'=>$user]); 
    } 
} 

//观点是

<script src="//code.jquery.com/jquery-1.12.3.js"></script> 
<script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> 
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script> 
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css"> 

<table class="table table-striped table-bordered" width="100%" cellspacing="0" id="table"> 
    //Loop here 
</table> 


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

它给我的错误:

TypeError: $(...).DataTable is not a function

我做了大部分R & D,但没有找到它的工作。请协助可能是这个问题。

有什么我需要做的,因为我已经在symfony2中使用它,它在那里工作。我也跟着this

谢谢提前

+0

在您的控制台:是有404吗? – Mruf

+0

检查数据表脚本是否正确包含? –

+0

回答

0

$(document).ready(function() { 
 
    $('#example').DataTable(); 
 
}); 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> 
 

 
    
 
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css"> 
 

 
    
 

 
    
 

 
    <table id="example" class="display" cellspacing="0" width="100%"> 
 

 
       <thead> 
 
     <tr> 
 
      <th >Name</th> 
 
      <th >Email</th> 
 
      <th >Joined</th> 
 
      <th colspan="2">Action1</th> 
 

 
     </tr> 
 
     <tr> 
 
     <th >Name</th> 
 
      <th >Email</th> 
 
      <th >Joined</th> 
 
      <th>edit</th> 
 
      <th>go</th> 
 
     </tr> 
 
    </thead> 
 
    <tfoot> 
 
     <tr> 
 
      <th> Name </th> 
 
      <th> Email </th> 
 
      <th> Joined </th> 
 
      <th>Action1</th> 
 
       <th>Action2</th> 
 

 
     </tr> 
 
    </tfoot> 
 
    <tbody> 
 
     <tr> 
 
<td>a</td> 
 
<td>b</td> 
 
<td>c</td> 
 
<td>d</td> 
 
<td>e</td> </tr> 
 
      </tbody> 
 
      </table>

这是一个工作的例子,我想在脚本中的问题包括其需要的HTTP和表 表合并单元格使用根据dataTable的 https://datatables.net/examples/basic_init/complex_header.html

+0

我不明白为什么不在我的页面上工作。甚至所有东西都包括在内。这个例子甚至不起作用。 Laravel刀片模板有问题吗? –

+0

你换了表吗?我的意思是它打印正确形式laravel? 检查代码,并把你的循环出来,然后我们将解决它 –

+0

$ (document).ready(function(){('#example')。数据表(); }); 是的,像上面 –

1

尝试关闭脚本正确标签:)

<script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>

+0

它的死亡,我忘了过去这里正确.. –

+0

它是'DataTable();' –

+0

我也试过这个以及: $ document).ready(function(){('#table').DataTables(); }); TypeError:$(...).DataTables不是函数 –

1
<script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"</script> 

请完成脚本标签。

+0

对不起,我忘了过去正确。它在实际代码中是关闭的。 –