yajra / laravel-datatables

jQuery DataTables API for Laravel
https://yajrabox.com/docs/laravel-datatables
MIT License
4.74k stars 861 forks source link

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

Open conangithub opened 11 months ago

conangithub commented 11 months ago

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

yajra commented 10 months ago

Tagging for enhancement as this is currently not supported.

The workaround is via column render for now.