Level 75
Aug 5, 2019
3
Level 2
How to add link on datatables into data in table
I have data on table using Model View Controller :
controller :
<tbody>
@php
$no=0;
@endphp
@foreach ($pns as $i)
<tr class="even pointer">
<td class="a-center ">{{ ++$no }}</td>
<td class=" "><a href="project/pns/{{ $i->id }}">{{ $i->users->nama}}</a></td>
<td class=" ">{{ $i->NIP_lama}}</td>
<td class=" ">{{ $i->NIP_baru}}</td>
<td class=" ">{{ $i->TMT_CPNS}}</td>
<td class=" ">{{ $i->TMT_PNS}}</td>
<td class=" ">{{ $i->TMT_gol_ruang}}</td>
<td class=" ">{{ $i->master_golongan->golongan}}</td>
<td class=" ">{{ $i->master_jabatan->nama_jabatan}}</td>
</tr>
@endforeach
</tbody>
And the Controller :
public function pns()
{
$pns = Data_pns::with('users')->get();
return view('admin.pns',['pns' => $pns]);
}
its run normally and not having error . now i want to add datatables yajra fitur , and its have 1 problem . I dont know how to add link :
<td class=" "><a href="project/pns/{{ $i->id }}">{{ $i->users->nama}}</a></td>
on the datatables :
My View :
@push('scripts')
<script>
$(function() {
$('#table').DataTable({
processing: true,
serverSide: true,
responsive: true,
ajax: '{!! route('d_pns') !!}',
columns: [
{ data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false,searchable: false},
{ data: 'users.nama', name: 'users.nama'},
{ data: 'NIP_lama', name: 'NIP_lama'},
{ data: 'NIP_baru', name: 'NIP_baru'},
{ data: 'TMT_CPNS', name: 'TMT_CPNS'},
{ data: 'TMT_PNS', name: 'TMT_PNS'},
{ data: 'TMT_gol_ruang', name: 'TMT_gol_ruang'},
{ data: 'master_golongan.golongan', name: 'master_golongan.golongan'},
{ data: 'master_jabatan.nama_jabatan', name: 'master_jabatan.nama_jabatan'},
],
});
})
</script>
@endpush
and my controller like this :
public function indexDataTables_pns()
{
$pns = Data_pns::with('users','master_golongan','master_jabatan')->get();
return Datatables::of($pns)->addIndexColumn()
->make(true);
}
#edit .
and my controller like this :
public function indexDataTables_pns()
{
$pns = Data_pns::with('users','master_golongan','master_jabatan')->get();
return Datatables::of($pns)->addIndexColumn()
->addColumn('Nama', function ($pns) {
return '<a href="project/pns/'.$pns->id.'">'.$pns->users->nama.'</a>';
})
->make(true);
}
but this output in view " <#a href="project/pns/5">test " *without '#'
my Question how to add link like
<td class=" "><a href="project/pns/{{ $i->id }}">{{ $i->users->nama}}</a></td>
on datatbles ?
Level 2
and my controller like this :
public function indexDataTables_pns()
{
$pns = Data_pns::with('users','master_golongan','master_jabatan')->get();
return Datatables::of($pns)->addIndexColumn()
->addColumn('Nama', function ($pns) {
return '<a href="project/pns/'.$pns->id.'">'.$pns->users->nama.'</a>';
})
->make(true);
}
but this output in view " test "
Please or to participate in this conversation.