Skip to content
Icon

WARNING You're browsing the documentation for an upcoming version of Laravel DataTables. The documentation and features of this release are subject to change.

HTML Builder Table

The table() method generates the HTML table markup for your DataTable.


Basic Usage

Simple Table

use Yajra\DataTables\Html\Builder;
 
echo $html->table();

Table with Custom Attributes

use Yajra\DataTables\Html\Builder;
 
echo $html->table([
'class' => 'table table-striped table-bordered',
'id' => 'users-table',
]);

Table with Footer

use Yajra\DataTables\Html\Builder;
 
echo $html->table(['class' => 'table'], true);

Table with Search Headers

use Yajra\DataTables\Html\Builder;
 
echo $html->table([], false, true);

Method Signature

public function table(array $attributes = [], bool $drawFooter = false, bool $drawSearch = false): HtmlString

Parameters

Parameter Type Default Description
$attributes array [] HTML table attributes
$drawFooter bool false Whether to draw <tfoot>
$drawSearch bool false Whether to draw search filter row

Complete Example

use Yajra\DataTables\Facades\DataTables;
use Yajra\DataTables\Html\Builder;
use Yajra\DataTables\Html\Column;
use App\Models\User;
 
Route::get('users', function(Builder $builder) {
if (request()->ajax()) {
return DataTables::of(User::query())->toJson();
}
 
$html = $builder->columns([
Column::make('name'),
Column::make('email'),
Column::make('id'),
]);
 
return view('users.index', compact('html'));
});

In your Blade template:

@extends('layouts.app')
 
@section('content')
{{ $html->table(['class' => 'table table-bordered']) }}
@endsection
 
@push('scripts')
{{ $html->scripts() }}
@endpush

See Also