如何将数据 table 上的 link 添加到 table 中的数据中
How to add link on datatables into data in table
我有关于 table 使用模型视图控制器的数据:
控制器:
<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>
控制器:
public function pns() {
$pns = Data_pns::with('users')->get();
return view('admin.pns',['pns' => $pns]);
}
它 运行 正常并且没有错误。现在我想添加 datatables yajra yajra 功能,但它有 1 个问题。 我不知道如何添加link :
<td class=" "><a href="project/pns/{{ $i->id }}">{{ $i->users->nama}}</a></td>
数据tables :
我的看法:
@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
我的控制器是这样的:
public function indexDataTables_pns()
{
$pns = Data_pns::with('users','master_golongan','master_jabatan')->get();
return Datatables::of($pns)->addIndexColumn()
->make(true);
}
编辑了这个控制器
我的控制器是这样的:
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);
}
但是这个输出在视图“<#a href="project/pns/5">test”中没有#
我的问题如何添加 link 喜欢
<td class=" "><a href="project/pns/{{ $i->id }}">{{ $i->users->nama}}</a></td>
在数据表上?
你已经完成一半了,你需要将 'Nama' 列设置为原始列,如果你要返回这样的 html 内容
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>';
})
->rawColumns(['Nama'])
->make(true);
}
我有关于 table 使用模型视图控制器的数据:
控制器:
<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>
控制器:
public function pns() {
$pns = Data_pns::with('users')->get();
return view('admin.pns',['pns' => $pns]);
}
它 运行 正常并且没有错误。现在我想添加 datatables yajra yajra 功能,但它有 1 个问题。 我不知道如何添加link :
<td class=" "><a href="project/pns/{{ $i->id }}">{{ $i->users->nama}}</a></td>
数据tables :
我的看法:
@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
我的控制器是这样的:
public function indexDataTables_pns()
{
$pns = Data_pns::with('users','master_golongan','master_jabatan')->get();
return Datatables::of($pns)->addIndexColumn()
->make(true);
}
编辑了这个控制器
我的控制器是这样的:
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);
}
但是这个输出在视图“<#a href="project/pns/5">test”中没有#
我的问题如何添加 link 喜欢
<td class=" "><a href="project/pns/{{ $i->id }}">{{ $i->users->nama}}</a></td>
在数据表上?
你已经完成一半了,你需要将 'Nama' 列设置为原始列,如果你要返回这样的 html 内容
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>';
})
->rawColumns(['Nama'])
->make(true);
}