Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change column names for view using DataTables

I’m using DataTables and AdminLTE in Laravel. And one of the things I want to do is make custom names for columns of the employees table in the view. For example image_path should become photo. Is there a way to do it inside the EmployeesDataTable?
Code inside EmployeesDataTable:

public function getColumns(): array
    {
        return [
            Column::make('image_path'),
            Column::make('name'),
            Column::make('position_id'),
            Column::make('recruitment_date'),
            Column::make('phone_number'),
            Column::make('email'),
            Column::make('payment'),
            Column::computed('action')
            ->exportable(false)
            ->printable(false)
            ->width(60)
            ->addClass('text-center'),
        ];
    }

View:


@section('title', 'Dashboard')

@section('content_header')
    <h1>Dashboard</h1>
@stop

@section('content')
<div class="container">
    <div class="card">
        <div class="card-header">Manage Employees</div>
        <div class="card-body">
            {{ $dataTable->table() }}
        </div>
    </div>
</div>
@stop

@section('css')
    <link rel="stylesheet" href="/css/admin_custom.css">
@stop

@push('scripts')
    {{ $dataTable->scripts(attributes: ['type' => 'module']) }}
@endpush


@section('js')
@stack('scripts')
@stop


Controller:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  public function index(EmployeesDataTable $dataTable)
    {

        return $dataTable->render('admin.employees.index');
    }

>Solution :

You should be able to just use ->title('Custom Column Title')

https://datatables.net/reference/option/columns.title

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading