Skip to content

Commit 0668a2b

Browse files
committed
Builder, table & columns docs.
1 parent eafa63a commit 0668a2b

File tree

4 files changed

+181
-2
lines changed

4 files changed

+181
-2
lines changed

documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
- [Whitelist Columns](/docs/laravel-datatables/{{version}}/whitelist)
5151
- HTML Builder
5252
- [Builder](/docs/laravel-datatables/{{version}}/html-builder)
53+
- [Table](/docs/laravel-datatables/{{version}}/html-builder-table)
5354
- [Columns](/docs/laravel-datatables/{{version}}/html-builder-column)
5455
- [Parameters](/docs/laravel-datatables/{{version}}/html-builder-parameters)
5556
- [Events/Callbacks](/docs/laravel-datatables/{{version}}/html-builder-callbacks)

html-builder-column.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
1-
# Html Builder Column
1+
# Html Builder Column
2+
3+
Builder Column represents the column to be rendered by your dataTables.
4+
You can use `addColumn` api to add a single column and `columns` api to add multiple columns.
5+
6+
<a name="attributes"></a>
7+
## Column Attributes
8+
9+
A DataTable `Column` accepts the following attributes:
10+
11+
```php
12+
$column = [
13+
'name' => 'id',
14+
'data' => 'id',
15+
'title' => 'Id',
16+
'searchable' => true,
17+
'orderable' => true,
18+
'render' => 'function(){}',
19+
'footer' => 'Id',
20+
'exportable' => true,
21+
'printable' => true,
22+
];
23+
```
24+
25+
You also need to look at [`datatables.net`](https://datatables.net/reference/option/columns) official columns documentation for further reference.
26+
27+
### Name (Optional)
28+
Name attribute represents the `column` name from your data source.
29+
Datatables will use this attribute when performing search and ordering functions.
30+
31+
> {tip} If not set, `name` attribute will automatically be set to same value as `data` attribute.
32+
33+
### Data
34+
Data attribute will be used when rendering the response to your table. This is the `key` from the `json` response `data` array.
35+
36+
### Title (Optional)
37+
Title attribute is used as your `table` column heading `<th>{{$title}}</th>`.
38+
39+
> {tip} If not set, `data` attribute value will be use as `title` with title case format.
40+
41+
### Searchable (Optional)
42+
Searchable attribute will toggle the `searching` ability for the defined column. Default value is `true`.
43+
44+
### Orderable (Optional)
45+
Orderable attribute will toggle the `ordering` ability for the defined column. Default value is `true`.
46+
47+
### Render (Optional)
48+
Render attribute is a `js` script string that you can use to modify the way the column is being rendered via `javascript`.
49+
50+
### Footer (Optional)
51+
Footer attribute will be as your `tables` column's `footer` content `<tfoot></tfoot>`.
52+
53+
> {tip} To display the footer using html builder, pass `true` as 2nd argument on `$builder->table([], true)` api.
54+
55+
56+
### Exportable (Optional)
57+
Exportable attribute will flag the column to be included when `exporting` the table. Default value is `true`.
58+
59+
> Exportable attribute should be used with the [Buttons Plugin](/docs/laravel-datatables/{{version}}/buttons-installation)
60+
61+
### Printable (Optional)
62+
Printable attribute will flag the column to be included when `printing` the table. Default value is `true`.
63+
64+
> Exportable attribute should be used with the [Buttons Plugin](/docs/laravel-datatables/{{version}}/buttons-installation)

html-builder-table.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Html Builder Table
2+
3+
Table api accepts two parameters: `$builder->table(array $attributes, $footer = false)`
4+
- `$attributes` represents an array that will be converted as your `<table></table>` attributes.
5+
- `$footer` will include/remove `<tfoot></tfoot>` on your `table` markup.
6+
7+
<a name="example"></a>
8+
## Table Example with Footer
9+
10+
```php
11+
use Datatables;
12+
use Yajra\Datatables\Html\Builder;
13+
14+
Route::get('users', function(Builder $builder) {
15+
if (request()->ajax()) {
16+
return Datatables::of(User::query())->make(true);
17+
}
18+
19+
$html = $builder->columns([
20+
['data' => 'id', 'footer' => 'Id'],
21+
['data' => 'name', 'footer' => 'Name'],
22+
['data' => 'email', 'footer' => 'Email'],
23+
['data' => 'created_at', 'footer' => 'Created At'],
24+
['data' => 'updated_at', 'footer' => 'Updated At'),
25+
]);
26+
27+
return view('users.index', compact('html'));
28+
});
29+
```
30+
31+
On your `resources/views/users/index.blade.php`.
32+
33+
```php
34+
@extends('app')
35+
36+
@section('contents')
37+
{!! $html->table(['class' => 'table table-bordered', true]) !!}
38+
@endsection
39+
40+
@push('scripts')
41+
{!! $html->scripts() !!}
42+
@endpush
43+
```

html-builder.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,73 @@
1-
# Html Builder
1+
# Html Builder
2+
3+
Datatables has a built-in html builder that you can use to automatically generate your table mark-up and javascripts declarations.
4+
5+
<a name="dependency-injection"></a>
6+
## Html Builder via Dependency Injection
7+
8+
You can use the `Builder` class by using Dependency Injection.
9+
10+
```php
11+
use Yajra\Datatables\Html\Builder;
12+
13+
Route::get('users', function(Builder $builder) {
14+
});
15+
```
16+
17+
<a name="ioc"></a>
18+
## Html Builder via IoC
19+
20+
```php
21+
Route::get('users', function() {
22+
$builder = app('datatables.html');
23+
});
24+
```
25+
26+
<a name="datatables-intance"></a>
27+
## Html Builder from Datatables instance
28+
29+
```php
30+
use Yajra\Datatables\Datatables;
31+
32+
Route::get('users', function(Datatables $dataTable) {
33+
$builder = $dataTable->getHtmlBuilder();
34+
});
35+
```
36+
37+
<a name="example"></a>
38+
## Html Builder Example
39+
40+
```php
41+
use Datatables;
42+
use Yajra\Datatables\Html\Builder;
43+
44+
Route::get('users', function(Builder $builder) {
45+
if (request()->ajax()) {
46+
return Datatables::of(User::query())->make(true);
47+
}
48+
49+
$html = $builder->columns([
50+
['data' => 'id', 'name' => 'id', 'title' => 'Id'],
51+
['data' => 'name', 'name' => 'name', 'title' => 'Name'],
52+
['data' => 'email', 'name' => 'email', 'title' => 'Email'],
53+
['data' => 'created_at', 'name' => 'created_at', 'title' => 'Created At'],
54+
['data' => 'updated_at', 'name' => 'updated_at', 'title' => 'Updated At']),
55+
]);
56+
57+
return view('users.index', compact('html'));
58+
});
59+
```
60+
61+
On your `resources/views/users/index.blade.php`.
62+
63+
```php
64+
@extends('app')
65+
66+
@section('contents')
67+
{!! $html->table() !!}
68+
@endsection
69+
70+
@push('scripts')
71+
{!! $html->scripts() !!}
72+
@endpush
73+
```

0 commit comments

Comments
 (0)