芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/DataTables/DesignationDataTable.php
editDesignationPermission = user()->permission('edit_designation'); $this->deleteDesignationPermission = user()->permission('delete_designation'); } /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { return datatables() ->eloquent($query) ->addIndexColumn() ->addColumn('check', function ($row) { return '
'; }) ->editColumn('name', function ($row) { $name = '
' . $row->name . '
'; return $name; }) ->editColumn('parent_id', function ($row) { // get name of parent designation $parent = Designation::where('id', $row->parent_id)->first(); if ($parent) { return $parent->name; } else { return '-'; } }) ->addColumn('action', function ($row) { $action = '
' . __('app.view') . '
'; if ($this->editDesignationPermission == 'all') { $action .= '
' . trans('app.edit') . '
'; } if ($this->deleteDesignationPermission == 'all') { $action .= '
' . trans('app.delete') . '
'; } $action .= '
'; return $action; }) ->smart(false) ->setRowId(function ($row) { return 'row-' . $row->id; }) ->rawColumns(['check', 'action', 'name']); } /** * @param Designation $model * @return \Illuminate\Database\Query\Builder */ public function query(Designation $model) { $request = $this->request(); $model = $model->select('*'); if (request()->searchText != '') { $model->where('name', 'like', '%' . request()->searchText . '%'); } if ($request->parentId != 'all' && $request->parentId != null) { $departments = Designation::with('childs')->where('id', $request->parentId)->get(); foreach ($departments as $department) { if ($department->childs) { $this->child($department->childs); array_push($this->arr, $department->id); } } $model->whereIn('id', $this->arr); } return $model; } public function child($child) { foreach ($child as $item) { $this->arr[] = $item->id; if ($item->childs) { $this->child($item->childs); } } } /** * Optional method if you want to use html builder. * * @return \Yajra\DataTables\Html\Builder */ public function html() { $dataTable = $this->setBuilder('Designation-table') ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["Designation-table"].buttons().container() .appendTo("#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { $("body").tooltip({ selector: \'[data-toggle="tooltip"]\' }); $(".statusChange").selectpicker(); }', ]); if (canDataTableExport()) { $dataTable->buttons(Button::make(['extend' => 'excel', 'text' => '
' . trans('app.exportExcel')])); } return $dataTable; } /** * Get columns. * * @return array */ protected function getColumns() { return [ 'check' => [ 'title' => '
', 'exportable' => false, 'orderable' => false, 'searchable' => false ], '#' => ['data' => 'DT_RowIndex', 'orderable' => false, 'searchable' => false, 'visible' => false, 'title' => '#'], __('app.name') => ['data' => 'name', 'name' => 'name', 'exportable' => true, 'title' => __('app.name')], __('app.menu.parent_id') => ['data' => 'parent_id', 'name' => 'parent_id', 'exportable' => true, 'title' => __('app.menu.parent_id') . ' ' . __('app.menu.designation')], Column::computed('action', __('app.action')) ->exportable(false) ->printable(false) ->orderable(false) ->searchable(false) ->addClass('text-right pr-20') ]; } }