芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/DataTables/DepartmentDataTable.php
editDepartmentPermission = user()->permission('edit_department'); $this->deleteDepartmentPermission = user()->permission('delete_department'); } /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { return datatables() ->eloquent($query) ->addColumn('check', function ($row) { return '
'; }) ->addColumn('action', function ($row) { $action = '
' . __('app.view') . '
'; if ($this->editDepartmentPermission == 'all') { $action .= '
' . trans('app.edit') . '
'; } if ($this->deleteDepartmentPermission == 'all') { $action .= '
' . trans('app.delete') . '
'; } $action .= '
'; return $action; }) ->editColumn( 'name', function ($row) { return '
' . $row->team_name . '
'; } ) ->editColumn('parent_id', function ($row) { // get name of parent department $parent = Team::where('id', $row->parent_id)->first(); if ($parent) { return $parent->team_name; } else { return '-'; } }) ->addIndexColumn() ->smart(false) ->setRowId(function ($row) { return 'row-' . $row->id; }) ->rawColumns(['action', 'name', 'check']); } /** * Get query source of dataTable. * * @param \App\Models\Team $model * @return \Illuminate\Database\Eloquent\Builder */ public function query(Team $model) { $request = $this->request(); $model = $model->select('*'); if (request()->searchText != '') { $model->where('team_name', 'like', '%' . request()->searchText . '%'); } if ($request->parentId != 'all' && $request->parentId != null) { $departments = Team::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) { array_push($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('departments-table', 2) ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["departments-table"].buttons().container() .appendTo("#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { $("body").tooltip({ selector: \'[data-toggle="tooltip"]\' }) }', ]); 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, 'visible' => !in_array('client', user_roles()) ], '#' => ['data' => 'DT_RowIndex', 'orderable' => false, 'searchable' => false, 'visible' => false, 'title' => '#'], __('app.name') => ['data' => 'name', 'name' => 'team_name', 'title' => __('app.name')], __('modules.department.parentDepartment') => ['data' => 'parent_id', 'name' => 'parent_id', 'exportable' => true, 'title' => __('modules.department.parentDepartment')], Column::computed('action', __('app.action')) ->exportable(false) ->printable(false) ->orderable(false) ->searchable(false) ->addClass('text-right pr-20') ]; } }