2

I'm working with Laravel 5 and Bootgrid Pagination. I'm planning to use it later so I'm learning it and playing around with it but I can't make it work. In my browser console I get

Uncaught TypeError: Cannot read property 'length' of undefined

I don't know if it is the data format that I'm passing.

Here's the html

<table id="grid-data" class="table table-condensed table-hover table-striped" data-toggle="bootgrid" data-ajax="true" data-url="api/deliverytracker">
    <thead>
        <tr>
            <th data-column-id="id" data-identifier="true">ID</th>
            <th data-column-id="sender">Sender</th>
            <th data-column-id="received">Recieved</th>
        </tr>
    </thead>    
</table>

in my route for api/deliverytracker

Route::any('api/deliverytracker', 'DeliveryTrackerController@deliveryIndexApi');

Then my function in my DeliveryTrackerController

public function deliveryIndexApi()
{
    $data = array(
        array('id' => '1', 'sender' => '123@test.de', 'received' => '2014-05-30T22:15:00'),
        array('id' => '2', 'sender' => '123@test.de', 'received' => '2014-05-30T22:15:00'),
        );

    return json_encode($data);
}

Did I missed something? I tried to console log my $data which turns out

[{"id":"1","sender":"123@test.de","received":"2014-05-30T22:15:00"},{"id":"2","sender":"123@test.de","received":"2014-05-30T22:15:00"}]

Thanks!

jackhammer013
  • 2,295
  • 11
  • 45
  • 95

1 Answers1

0

You need to return the JSON correctly .

$data = array(
        "current" => 1,
        "rowCount" => 10,
        "rows" => array(
         array('id' => '1', 'sender' => '123@test.de', 'received' => '2014-05-30T22:15:00'),
         array('id' => '2', 'sender' => '123@test.de', 'received' => '2014-05-30T22:15:00')
         ),
        "total" => 1123
       );

check official documentation http://www.jquery-bootgrid.com/Examples#data