Laravel-datatables: Multiple data values to one column

Created on 2 Mar 2017  路  5Comments  路  Source: yajra/laravel-datatables

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?

Most helpful comment

Fixed it!

return Datatables::of($advicePreparationsQuery)
            ->addColumn('mergeColumn', function($row){
                return '-'.$row->category_name1.'    -'.$row->category_name2.'    -'.$row->category_name3;
            })
            ->make(true);

All 5 comments

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 '





';
})
->make(true);

javascript code

{
data: 'ttl',
name: 'ttl'
}
```
DeepinScreenshot_select-area_20191125092912

Done!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ezekel picture ezekel  路  17Comments

ruchisheth picture ruchisheth  路  16Comments

mithleshjs picture mithleshjs  路  16Comments

ezani92 picture ezani92  路  33Comments

ZAZmaster picture ZAZmaster  路  15Comments