Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to hide whole action column while printing? #3210

Open
maulik1211 opened this issue Jan 10, 2025 · 2 comments
Open

How to hide whole action column while printing? #3210

maulik1211 opened this issue Jan 10, 2025 · 2 comments

Comments

@maulik1211
Copy link

Summary of problem or feature request

How can I hide the whole 'action' column while print preview and exporting?

I tried solutions from this question, but it hides content only.

I do not want the title 'Action' to be printed or exported.

How to achieve this?

Code snippet of problem

Screenshot from 2025-01-10 13-36-35

@yajra
Copy link
Owner

yajra commented Jan 10, 2025

Just set the column as printable(false).

Column::make(x)->printable(false);

@maulik1211
Copy link
Author

Thanks @yajra for your reply. But it does not work. here is my code.

I am trying for the status column, but it still appears in Print Preview and Export. However, it works for Orderable.

I am using package version: 10.1

Please let me know if I am doing anything wrong. Thanks.

`public function dataTable($query)
{
$dataTable = new EloquentDataTable($query);

    $query->leftJoin('organisations', function ($join) {
        $join->on('organisations.id', '=', 'trips.company_id');
    });
    $query->select([
        'trips.id',
        DB::raw('organisations.english_name as organisation'),
        'trips.name',
        'trips.status',
    ]);

    $dataTable->editColumn('id', function ($data) {
        return '<input type="checkbox" class="bulk bulk_ops" name="bulk_ops[]" value="' . $data->id . '" id="deleteMe' . $data->id . '">';
    });

    $dataTable->editColumn('status', function ($data) {
        $enable = $data->status == \App\Models\Vehicle::ENABLE;
        $status = $enable ? 'Enable' : 'Disable';
        $badgeClass = $enable ? 'bg-success' : 'bg-danger';

        return "<span class='badge {$badgeClass}'>{$status}</span>";
    });

    $dataTable->rawColumns(['id', 'status']);
    return $dataTable;
}

/**
 * Get query source of dataTable.
 *
 * @return \Illuminate\Database\Eloquent\Builder
 */
public function query(RoutePlan $model)
{
    return $model->newQuery();
}

/**
 * Optional method if you want to use html builder.
 *
 * @return \Yajra\DataTables\Html\Builder
 */
public function html()
{
    return $this->builder()
        ->columns($this->getColumns())
        ->minifiedAjax()
        ->addAction(['width' => '120px', 'printable' => false, 'class' => 'text-center'])
        ->parameters(DataTableHelper::datatableSetting());
}

/**
 * Get columns.
 *
 * @return array
 */
protected function getColumns()
{
    return [
        Column::make('id')
            ->name('id')
            ->title('<input type="checkbox" class="bulk select_all" name="select_all" value="" id="select_all"/>')
            ->orderable(false)
            ->searchable(false)
            ->width('50px')
            ->addClass('text-center'),

        Column::make('organisation')
            ->name('organisation')
            ->title('Organisation'),

        Column::make('name')
            ->name('name')
            ->title('Trip title')
            ->orderable(true)
            ->searchable(true),

        Column::make('status')
            ->name('status')
            ->title('Status')
            ->orderable(false)
            ->exportable(false)
            ->printable(false)
            ->addClass('text-center'),
    ];
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants