-
-
Notifications
You must be signed in to change notification settings - Fork 495
/
ProductDataGrid.php
107 lines (95 loc) · 2.63 KB
/
ProductDataGrid.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Webkul\Admin\DataGrids\Product;
use Webkul\UI\DataGrid\DataGrid;
use Illuminate\Support\Facades\DB;
class ProductDataGrid extends DataGrid
{
/**
* Prepare query builder.
*
* @return void
*/
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('products')
->addSelect(
'products.id',
'products.sku',
'products.name',
'products.price',
'products.quantity'
);
$this->addFilter('id', 'products.id');
$this->setQueryBuilder($queryBuilder);
}
/**
* Add columns.
*
* @return void
*/
public function addColumns()
{
$this->addColumn([
'index' => 'sku',
'label' => trans('admin::app.datagrid.sku'),
'type' => 'string',
'sortable' => true,
]);
$this->addColumn([
'index' => 'name',
'label' => trans('admin::app.datagrid.name'),
'type' => 'string',
'sortable' => true,
]);
$this->addColumn([
'index' => 'price',
'label' => trans('admin::app.datagrid.price'),
'type' => 'string',
'sortable' => true,
'closure' => function ($row) {
return round($row->price, 2);
},
]);
$this->addColumn([
'index' => 'quantity',
'label' => trans('admin::app.datagrid.quantity'),
'type' => 'string',
'sortable' => true,
]);
}
/**
* Prepare actions.
*
* @return void
*/
public function prepareActions()
{
$this->addAction([
'title' => trans('ui::app.datagrid.edit'),
'method' => 'GET',
'route' => 'admin.products.edit',
'icon' => 'pencil-icon',
]);
$this->addAction([
'title' => trans('ui::app.datagrid.delete'),
'method' => 'DELETE',
'route' => 'admin.products.delete',
'confirm_text' => trans('ui::app.datagrid.massaction.delete', ['resource' => 'user']),
'icon' => 'trash-icon',
]);
}
/**
* Prepare mass actions.
*
* @return void
*/
public function prepareMassActions()
{
$this->addMassAction([
'type' => 'delete',
'label' => trans('ui::app.datagrid.delete'),
'action' => route('admin.products.mass_delete'),
'method' => 'PUT',
]);
}
}