无法隐藏yajra datatables oracle中的列

问题描述 投票:0回答:1

我正在使用yajrda datatables oracle包来管理数据。我正在使用数据表的服务实现。我面临的问题是我无法隐藏数据表中的某些列。

我想隐藏列名ID_Centro但它没有发生。这是该类的代码。

<?php

namespace App\DataTables;

use App\Model\Theater;
use Yajra\Datatables\Services\DataTable;

class TheaterDataTable extends DataTable
{
    /**
     * Build DataTable class.
     *
     */
    public function dataTable()
    {

        return $this->datatables
            ->eloquent($this->query())
            ->addColumn('action',function ($theater){
                if (auth()->user()->hasPermission("CinesFull")){
                    return "
        <a href=\"".route("theater.edit",$theater->ID_Centro)."\" class=\"btn btn-success \" >".trans("action.edit")."</a> ".
                        "<a  href=\"#\" onclick=\"deleteItem('$theater->ID_Centro')\" class=\"btn btn-danger\">".trans("action.delete")."</a>";
                }else{
                    return "";
                }

            });
    }

    /**
     * Get the query object to be processed by dataTables.
     *
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
     */
    public function query()
    {
    $query = Theater::query()->select($this->getColumns());

        return $this->applyScopes($query);
    }

    /**
     * Optional method if you want to use html builder.
     *
     * @return \Yajra\Datatables\Html\Builder
     */
    public function html()
    {
        return $this->builder()
            ->columns([
                [
                    'name'=>'ID_Centro'
                ]
            ])
            ->minifiedAjax('')
            ->addAction(['printable' => false])
            ->parameters([
                'dom'     => 'Bfrtip',
                'order'   => [[0, 'desc']],
                'buttons' => [
                    'print'
                ],
            ]);
    }

    /**
     * Get columns.
     *
     * @return array
     */
    protected function getColumns()
    {
        return [
            [
                'name'=>'ID_Centro',
                'data'=>'ID_Centro',
                'title'=>'ID_Centro'
            ]
        ];
//             return  [
//                 [
//                     "orderable" => true,
//                     "searchable" => true,
//                     "title" => "ID_Centro",
//                     "data" => "ID_Centro"
//                 ],
//                 [
//                     'name' => 'type_id',
//                     "searchable" => false,
//                     "title" => "Type",
//                     "data" => "type",
//                 ],
//                 [
//                     'name' => 'tag',
//                     "searchable" => false,
//                     "title" => "Tag",
//                     "data" => "tag",
//                     "visible" => false,
//                 ],
//             ];
//            'ID_Centro',
//            'Nombre',
//            'LocalidadCentro',
//            'ProvinciaCentro',
//            'Tlfno1',
//            'Email',
//            ];
    }

    /**
     * Get filename for export.
     *
     * @return string
     */
    protected function filename()
    {
        return 'theater_' . time();
    }
}

我在实现它时遇到此错误。

Exception Message:↵↵strtolower() expects parameter 1 to be string, array given"

任何人都可以帮我解决这个问题。

laravel yajra-datatable
1个回答
0
投票

https://github.com/yajra/laravel-datatables

https://yajrabox.com/docs/laravel-datatables/master/installation

https://datatables.yajrabox.com

yajratable的几个链接文档....

尝试更改...的回复 - > addColumn

在Laravel中,在控制器中返回html并不是真正的类型。

public function dataTable(){

    return $this->datatables
        ->eloquent($this->query())
        ->addColumn('action',function ($theater){
            if (auth()->user()->hasPermission("CinesFull")){
                return "
    <a href=\"".route("theater.edit",$theater->ID_Centro)."\" class=\"btn btn-success \" >".trans("action.edit")."</a> ".
                    "<a  href=\"#\" onclick=\"deleteItem('$theater->ID_Centro')\" class=\"btn btn-danger\">".trans("action.delete")."</a>";
            }else{
                return "";
            }

        });
}
© www.soinside.com 2019 - 2024. All rights reserved.