Chumper / Datatable

This is a laravel 4 package for the server and client side of datatables at http://datatables.net/
https://github.com/Chumper/Datatable
388 stars 154 forks source link

help me i got error #250

Open Dewilas opened 9 years ago

Dewilas commented 9 years ago

Hi,

i got error: DataTables warning: table id=transactions_table - Ajax error. For more information about this error, please see http://datatables.net/tn/7

there is my js code:

var oTable = $('#transactions_table').DataTable({ "processing": true, "serverSide": true, "ajax": "/user/payments?type=datatable" }); $('#transactions_table').dataTable().api(); new $.fn.dataTable.Api('#transactions_table');

//console.debug(oTable);  
$('.search-box').keyup(function(){
      oTable.search($(this).val()).draw();
})

then i have html blade:

name name name name

there is my controler:

public function getIndex() { if(Request::ajax()) { switch(Input::get('type')) {

            case 'datatable':
                $result = DB::table('payments')
                          ->select('payments.id as id', 'payments.type', 'payments.amount', 'payments.created_at')
                          ->where('user_id', 17);
                return Datatable::collection($result)
                        ->make();
            break;
            default:
                return Response::json( array() );
        }
    }

please help my, where is my mistake

vardump $result return array:

array(2) { [0]=> object(stdClass)#803 (4) { ["id"]=> string(2) "44" ["type"]=> string(10) "creditcard" ["amount"]=> string(3) "100" ["created_at"]=> string(19) "2015-02-25 19:05:36" } [1]=> object(stdClass)#802 (4) { ["id"]=> string(2) "45" ["type"]=> string(6) "paypal" ["amount"]=> string(3) "100" ["created_at"]=> string(19) "2015-02-25 19:06:16" } }

timgws commented 9 years ago

You most likely do not want to be using Datatable::collection, but rather, Datatable::query, as you are passing a QueryBuilder.

Dewilas commented 9 years ago

i found the solution. issue locked