|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\DataTables; |
|
4
|
|
|
|
|
5
|
|
|
use App\Device; |
|
6
|
|
|
use Yajra\Datatables\Services\DataTable; |
|
7
|
|
|
|
|
8
|
|
|
class DevicesDataTable extends DataTable |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Build DataTable class. |
|
12
|
|
|
* |
|
13
|
|
|
* @return \Yajra\Datatables\Engines\BaseEngine |
|
14
|
|
|
*/ |
|
15
|
|
|
public function dataTable() |
|
16
|
|
|
{ |
|
17
|
|
|
return $this->datatables |
|
18
|
|
|
->eloquent($this->query()) |
|
19
|
|
|
->addColumn('action', 'device.action') |
|
20
|
|
|
->blacklist(['action']) |
|
21
|
|
|
->setRowClass(function ($device) { |
|
22
|
|
|
return $device->trashed() ? 'alert-danger' : ""; |
|
23
|
|
|
}); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get the query object to be processed by dataTables. |
|
28
|
|
|
* |
|
29
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
30
|
|
|
*/ |
|
31
|
|
|
public function query() |
|
32
|
|
|
{ |
|
33
|
|
|
$query = Device::query() |
|
|
|
|
|
|
34
|
|
|
->select([ |
|
35
|
|
|
'devices.id as id', |
|
36
|
|
|
'devices.name as name', |
|
37
|
|
|
'locations.name as location', |
|
38
|
|
|
'sites.name as site' |
|
39
|
|
|
]) |
|
40
|
|
|
->leftJoin('locations', 'devices.location_id', '=', 'locations.id') |
|
41
|
|
|
->leftJoin('sites', 'locations.site_id', '=', 'sites.id'); |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
return $this->applyScopes($query); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Optional method if you want to use html builder. |
|
49
|
|
|
* |
|
50
|
|
|
* @return \Yajra\Datatables\Html\Builder |
|
51
|
|
|
*/ |
|
52
|
|
View Code Duplication |
public function html() |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
return $this->builder() |
|
55
|
|
|
->columns($this->getColumns()) |
|
56
|
|
|
//->minifiedAjax('') |
|
57
|
|
|
//->addAction(['width' => '160px']) |
|
|
|
|
|
|
58
|
|
|
->parameters([ |
|
59
|
|
|
'dom' => 'Bfrtip', |
|
60
|
|
|
'order' => [[0, 'asc']], |
|
61
|
|
|
'buttons' => [ |
|
62
|
|
|
'export', |
|
63
|
|
|
'print', |
|
64
|
|
|
'reset', |
|
65
|
|
|
'reload', |
|
66
|
|
|
], |
|
67
|
|
|
'paging' => true, |
|
68
|
|
|
'searching' => true, |
|
69
|
|
|
'info' => true, |
|
70
|
|
|
'searchDelay' => 500, |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get columns. |
|
76
|
|
|
* |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function getColumns() |
|
80
|
|
|
{ |
|
81
|
|
|
return [ |
|
82
|
|
|
'id', |
|
83
|
|
|
'name', |
|
84
|
|
|
'location', |
|
85
|
|
|
'site', |
|
86
|
|
|
['name' => 'action', 'data' => 'action', 'title' => 'Actions', 'render' => null, 'searchable' => false, 'orderable' => false, 'exportable' => false, 'printable' => true, 'footer' => ''], |
|
87
|
|
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Get filename for export. |
|
92
|
|
|
* |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function filename() |
|
96
|
|
|
{ |
|
97
|
|
|
return 'devices_' . time(); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.