2016-03-26 52 views
1

我已經安裝了yajra/laravel-datatables-oracle「〜6.0」包,用於支持laravel 5.2中的服務器端數據表,以MySql作爲數據庫。 我試圖顯示用戶的數據表:Yajra Datatables包Laravel deosnt與laravel 5.2正常工作

//routes.php 
Route::group(['middleware' => ['web'], 'prefix' => 'user'], function() { 
    Route::get('/index', '[email protected]')->name('user.index'); 
}); 

,這裏是我的控制器:

//UserController.php 
public function index() 
{ 
    return view('user.index'); 
} 

public function indexData() 
{ 
    $users = User::select(['id', 'name', 'email', 'created_at', 'updated_at'])->get(); 
    return Datatables::of($users)->make(); 
} 

的觀點:

// user\index.blade.php 
@extends('layouts.base') 

@section('additional_styles') 
    <link rel="stylesheet" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css"> 
@endsection 

@section('additional_scripts') 
    <!-- DataTables --> 
    <script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script> 
    <script> 
     $('#users-table').DataTable({ 
      "processing": true, 
      "serverSide": true, 
      "ajax": '{!! route('user.index') !!}', 
      "columns": [ 
       {data: 'id', name: 'id'}, 
       {data: 'name', name: 'name'}, 
       {data: 'email', name: 'email'}, 
       {data: 'created_at', name: 'created_at'}, 
       {data: 'updated_at', name: 'updated_at'} 
      ] 
     }); 
    </script> 
@endsection 


@section('main-content') 
    <div class="container"> 
     <div class="row"> 
      <div class="col-md-10 col-md-offset-1"> 
       <div class="panel panel-default"> 
        <div class="panel-body"> 
         <table class="table table-bordered" id="users-table"> 
          <thead> 
          <tr> 
           <th>Id</th> 
           <th>Name</th> 
           <th>Email</th> 
           <th>Created At</th> 
           <th>Updated At</th> 
          </tr> 
          </thead> 
         </table> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
@endsection 

但數據表不能正常工作。經過處理以呈現數據後,它會向我顯示響應具有無效JSON格式的提示,並說要查看datatables.net/tn/1。我試圖看到chith的開發人員工具看到響應,但我不能!

有關這個問題的任何想法?

+0

這個問題對我來說太 –

回答

0

現在它在laravel 5.2.31工作,

`  Route 
    Route::get('datatables',['uses'=>'[email protected]', 'as' => 'datatables']); 
    Route::get('datatables/{data}',['uses'=>'[email protected]', 'as' => 'datatables.data']); 

    Controller 
     public function anyData() 
     { 
      $users = User::select(['id', 'name', 'email', 'created_at', 'updated_at'])->get(); 
     return Datatables::of($users)->make(); 
     } 

    JS 
    $('#users-table').DataTable({ 
      processing: true, 
      serverSide: true, 
      ajax: '{!! url('datatables/data') !!}' 
     });`