Skip to content
Arjay Angeles edited this page May 20, 2015 · 2 revisions

Getting started is simple. Just create your view and controller like below and make sure that you register your routes.

Route

Route::controllers([
    'auth'       => 'Auth\AuthController',
    'password'   => 'Auth\PasswordController',
    'demo'       => 'DemoController',
]);

Controller

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\User;
use Datatables;

class DemoController extends Controller
{

    public function getIndex()
    {
        return view('datatables.demo');
    }

    public function getData()
    {
        $users = User::select(['id', 'name', 'email', 'created_at', 'updated_at']);

        return Datatables::of($users)->make(true);
    }

}

View

<table id="users-table" class="table table-condensed">
    <thead>
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Email</th>
        <th>Created At</th>
        <th>Updated At</th>
    </tr>
    </thead>
</table>

$(function() {
	$('#users-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: '{{ url("demo/data") }}',
        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'}
        ]
    });
});