'documents.title', 'label' => trans('documents::documents.form.title'), 'type' => 'string', ], [ 'id' => 'documents.notes', 'label' => trans('documents::documents.form.notes'), 'type' => 'string', ], [ 'id' => 'documents.document_type_id', 'label' => trans('documents::documents.form.document_type_id'), 'type' => 'integer', 'input' => 'select', 'multiple' => true, 'plugin' => 'select2', 'plugin_config' => [ 'multiple' => 'multiple', 'width' => '300px', ], 'values' => DocumentType::pluck('name', 'id'), 'operators' => [ 'in', 'not_in', 'is_null', 'is_not_null' ] ], [ 'id' => 'documents.document_status_id', 'label' => trans('documents::documents.form.document_status_id'), 'type' => 'integer', 'input' => 'select', 'multiple' => true, 'plugin' => 'select2', 'plugin_config' => [ 'multiple' => 'multiple', 'width' => '300px', ], 'values' => DocumentStatus::pluck('name', 'id'), 'operators' => [ 'in', 'not_in', 'is_null', 'is_not_null' ] ], [ 'id' => 'documents.document_category_id', 'label' => trans('documents::documents.form.document_category_id'), 'type' => 'integer', 'input' => 'select', 'multiple' => true, 'plugin' => 'select2', 'plugin_config' => [ 'multiple' => 'multiple', 'width' => '300px', ], 'values' => DocumentCategory::pluck('name', 'id'), 'operators' => [ 'in', 'not_in', 'is_null', 'is_not_null' ] ], [ 'id' => 'documents.created_at', 'label' => trans('core::core.table.created_at'), 'type' => 'date', 'input_event' => 'dp.change', 'plugin' => 'datetimepicker', 'plugin_config' => [ 'locale' => app()->getLocale(), 'calendarWeeks' => true, 'showClear' => true, 'showTodayButton' => true, 'showClose' => true, 'format' => \Modules\Platform\Core\Helper\UserHelper::userJsDateFormat() ] ], [ 'id' => 'documents.updated_at', 'label' => trans('core::core.table.updated_at'), 'type' => 'date', 'input_event' => 'dp.change', 'plugin' => 'datetimepicker', 'plugin_config' => [ 'locale' => app()->getLocale(), 'calendarWeeks' => true, 'showClear' => true, 'showTodayButton' => true, 'showClose' => true, 'format' => \Modules\Platform\Core\Helper\UserHelper::userJsDateFormat() ] ], ]; } public static function availableColumns() { return [ 'title' => [ 'data' => 'title', 'title' => trans('documents::documents.form.title'), 'data_type' => 'text', 'filter_type' => 'text' ], 'category' => [ 'name' => 'documents_dict_category.name', 'data' => 'category', 'title' => trans('documents::documents.form.document_category_id'), 'data_type' => 'text', 'filter_type' => 'text' ], 'status' => [ 'name' => 'documents_dict_status.name', 'data' => 'status', 'title' => trans('documents::documents.form.document_status_id'), 'data_type' => 'text', 'filter_type' => 'text' ], 'type' => [ 'name' => 'documents_dict_type.name', 'data' => 'type', 'title' => trans('documents::documents.form.document_type_id'), 'data_type' => 'text', 'filter_type' => 'text' ], 'created_at' => [ 'data' => 'created_at', 'title' => trans('core::core.table.created_at'), 'data_type' => 'datetime', 'filter_type' => 'bap_date_range_picker', ], 'updated_at' => [ 'data' => 'updated_at', 'title' => trans('core::core.table.updated_at'), 'data_type' => 'datetime', 'filter_type' => 'bap_date_range_picker', ], 'owner' => [ 'data' => 'owner', 'title' => trans('core::core.table.assigned_to'), 'data_type' => 'assigned_to', 'orderable' => false, 'filter_type' => 'select', 'select_type' => 'select2', 'select_type_options' => [ 'theme' => "bootstrap", 'width' => '100%' ], 'filter_data' => DataTableHelper::filterOwnerDropdown() ] ]; } protected function setFilterDefinition() { $this->filterDefinition = self::availableQueryFilters(); } /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { $dataTable = new EloquentDataTable($query); $this->applyLinks($dataTable, self::SHOW_URL_ROUTE); $dataTable->filterColumn('owner', function ($query, $keyword) { DataTableHelper::queryOwner($query, $keyword,'documents'); }); $dataTable->filterColumn('created_at', function ($query, $keyword) { $dates = DataTableHelper::getDatesForFilter($keyword); if ($dates != null) { $query->whereBetween('documents.created_at', array($dates[0], $dates[1])); } }); $dataTable->filterColumn('updated_at', function ($query, $keyword) { $dates = DataTableHelper::getDatesForFilter($keyword); if ($dates != null) { $query->whereBetween('documents.updated_at', array($dates[0], $dates[1])); } }); return $dataTable; } /** * Get query source of dataTable. * * * @return \Illuminate\Database\Eloquent\Builder */ public function query(Document $model) { $query = $model->newQuery() ->with('owner') ->leftJoin('documents_dict_category','documents.document_category_id','=','documents_dict_category.id') ->leftJoin('documents_dict_status','documents.document_status_id','=','documents_dict_status.id') ->leftJoin('documents_dict_type','documents.document_type_id','=','documents_dict_type.id') ->select( 'documents.*', 'documents_dict_category.name as category', 'documents_dict_status.name as status', 'documents_dict_type.name as type' ); if (!empty($this->filterRules)) { $queryBuilderParser = new QueryBuilderParser(); $queryBuilder = $queryBuilderParser->parse($this->filterRules, $query); return $queryBuilder; } return $query; } /** * Optional method if you want to use html builder. * * @return \Yajra\DataTables\Html\Builder */ public function html() { return $this->builder() ->columns($this->getColumns()) ->setTableAttribute('class', 'table table-hover') ->parameters([ 'dom' => 'lBfrtip', 'responsive' => false, 'stateSave' => true, 'filterDefinitions' => $this->getFilterDefinition(), 'filterRules' => $this->filterRules, 'headerFilters' => true, 'buttons' => DataTableHelper::buttons(), 'regexp' => true ]); } /** * @return array */ protected function getColumns() { if (!empty($this->advancedView)) { $result = []; if ($this->allowSelect) { $result = $this->btnCheck_selection; } return $result + $this->advancedView; } $columns = self::availableColumns(); $result = []; if ($this->allowSelect) { $result = $this->btnCheck_selection; } if ($this->allowUnlink) { $result = $this->btnUnlink ; } if ($this->allowQuickEdit) { $result = $result + $this->btnQuick_edit; ; } $result = $result + $columns; return $result; } }