Laravel-datatables: Right way to hide/remove columns in views?

Created on 27 Feb 2017  路  1Comment  路  Source: yajra/laravel-datatables

Summary of problem or feature request

hi, what is the right way to hide columns shown in the views?

Code snippet of problem

I tried using:

    public function query()
    {
        $restaurants = restaurants::query();

        return $this->applyScopes($restaurants->removeColumn('password')->make(true));
    }

in the xxxxdataTable.php in App\DataTables

but I am getting:
http://prntscr.com/ee1lnz

But If I comment out the code in private function getColumns() of xxxxdataTable.php in App\DataTables

    /**
     * Get columns.
     *
     * @return array
     */
    private function getColumns()
    {
        return [
            'res_name' => ['name' => 'res_name', 'data' => 'res_name'],
//            'res_image' => ['name' => 'res_image', 'data' => 'res_image'],
//            'res_image_date' => ['name' => 'res_image_date', 'data' => 'res_image_date'],
            'res_address' => ['name' => 'res_address', 'data' => 'res_address'],
            'res_state' => ['name' => 'res_state', 'data' => 'res_state'],
            'res_location' => ['name' => 'res_location', 'data' => 'res_location'],
            'res_area' => ['name' => 'res_area', 'data' => 'res_area'],
//            'res_telephone' => ['name' => 'res_telephone', 'data' => 'res_telephone'],
//            'res_min_price' => ['name' => 'res_min_price', 'data' => 'res_min_price'],
//            'res_max_price' => ['name' => 'res_max_price', 'data' => 'res_max_price'],
//            'res_latitude' => ['name' => 'res_latitude', 'data' => 'res_latitude'],
//            'res_longitude' => ['name' => 'res_longitude', 'data' => 'res_longitude'],
//            'res_chain' => ['name' => 'res_chain', 'data' => 'res_chain'],
//            'res_new' => ['name' => 'res_new', 'data' => 'res_new'],
//            'res_offer' => ['name' => 'res_offer', 'data' => 'res_offer'],
//            'res_type_state' => ['name' => 'res_type_state', 'data' => 'res_type_state']
        ];
    }

it wont return any error, is this the right way to hide the columns?

System details

none

question

Most helpful comment

Use 'visible' => false in the column attributes.

'res_telephone' => ['name' => 'res_telephone', 'data' => 'res_telephone','visible' => false]

>All comments

Use 'visible' => false in the column attributes.

'res_telephone' => ['name' => 'res_telephone', 'data' => 'res_telephone','visible' => false]
Was this page helpful?
0 / 5 - 0 ratings