yajra / laravel-datatables

jQuery DataTables API for Laravel

Home Page:https://yajrabox.com/docs/laravel-datatables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't render html or edit index column in laravel controller side

conangithub opened this issue · comments

Summary of problem or feature request

I have index and id columns. I need to modify index column contents to become button link using index value. I need to modify it using render option in blade. Any way to do it in controller?

Code snippet of problem

I need something like this

$result = DB::select('SELECT id, a, b, c FROM my_tables');

$dt = $dataTables->make($result)
            ->addIndexColumn(
               modify to <a href='mylink' class='btn-primary'>index value</a>
            )
            ->rawColumns(['detail'])
            ->toJson();

I can do it in blade like this but I prefer to do it in controller like above.

columns: [
      {data: 'DT_RowIndex', name: 'DT_RowIndex', title: 'No.', render: function(data, type, full, meta) {
          return '<a class="btn-primary" href="mylink">' + data + '</a>';
      }},
]

For additional info, mylink contains value from another column in same table.

System details

  • Operating System : Mac OS Ventura 13.6
  • PHP Version : 8.0
  • Laravel Version : 6.0
  • Laravel-Datatables Version : 9.21.2

Tagging for enhancement as this is currently not supported.

The workaround is via column render for now.