Home > Software design >  How to change column names for view using DataTables
How to change column names for view using DataTables

Time:12-15

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 >
    <div >
        <div >Manage Employees</div>
        <div >
            {{ $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:

  public function index(EmployeesDataTable $dataTable)
    {

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

CodePudding user response:

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

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

  • Related