Hi everyone!
I am trying to add multiple data values into one column. I have seen some solutions on the internet, but it doesn't seem to help my problem. The data values category_name1, category_name2 and category_name3 need to be rendered into the same column. The JavaScript which i have now:
<script type="text/javascript">
$(document).ready(function() {
oTable = $('#advicePreparations-table').DataTable({
"processing": true,
"serverSide": true,
"ajax": "{{ route('advice_protocols.data') }}",
"columns": [
{data: 'name', name: 'name'},
{data: 'category', name: 'category'},
{data: 'question_name', name: 'goal'}
]
});
});
</script>
Could someone help me with getting the three data values into one column?
Fixed it!
return Datatables::of($advicePreparationsQuery)
->addColumn('mergeColumn', function($row){
return '-'.$row->category_name1.' -'.$row->category_name2.' -'.$row->category_name3;
})
->make(true);
can u plz explain how you fixed it, thanks.
piyush9620
have a look at the following for an explanation. Its been a very usefull resource for me.
https://yajrabox.com/docs/laravel-datatables/master/add-column
@annajeanine hey, the solution you provided above works, it does the descending sort but it does not do ascending sort, is it working fine for you ??
can u plz explain how you fixed it, thanks.
controller code
```
$staff = Staff::all('id', 'fullname', 'nickname', 'id_jabatan', 'tempat_lahir', 'tanggal_lahir', 'kontak', 'alamat');
return Datatables::of($staff)
->addColumn('ttl', function ($staff) {
return $staff->tempat_lahir . ', ' . $staff->tanggal_lahir;
})
->addColumn('action', function ($staff) {
return '
javascript code
{
data: 'ttl',
name: 'ttl'
}
```

Done!
Most helpful comment
Fixed it!