Perbaikan API Dawai
This commit is contained in:
@@ -42,17 +42,13 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($allPegawais as $index => $peg)
|
||||
@foreach ($allPegawais as $index => $peg)
|
||||
<tr class="atasan-row" data-nip="{{ $peg->nip }}" data-nama="{{ $peg->nama }}">
|
||||
<td>{{ $index + 1 }}</td>
|
||||
<td class="text-center">{{ $index + 1 }}</td>
|
||||
<td>{{ $peg->nama }}</td>
|
||||
<td>{{ $peg->nip }}</td>
|
||||
<td class="text-center">{{ $peg->nip }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="3" class="text-center text-muted py-3">Tidak ada data atasan</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -143,7 +139,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-striped table-bordered w-100 mb-0">
|
||||
<table id="modalBawahanTable" class="table table-sm table-striped table-bordered w-100 mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="40">No</th>
|
||||
@@ -467,13 +463,51 @@
|
||||
const modalEl = document.getElementById('modalBawahan');
|
||||
const modalBawahan = new bootstrap.Modal(modalEl);
|
||||
|
||||
function renderModalTable() {
|
||||
const $body = $('#modalBawahanBody').empty();
|
||||
// Nomor urut ulang setelah search/sort/paging
|
||||
function renumber(table) {
|
||||
const start = table.page.info().start;
|
||||
table.column(0, {
|
||||
search: 'applied',
|
||||
order: 'applied',
|
||||
page: 'current'
|
||||
}).nodes().each(function(cell, i) {
|
||||
cell.innerHTML = start + i + 1;
|
||||
});
|
||||
}
|
||||
|
||||
if (currentBawahan.length === 0) {
|
||||
$body.append('<tr><td colspan="4" class="text-center text-muted py-3">Belum ada bawahan yang ditugaskan</td></tr>');
|
||||
return;
|
||||
// Daftar atasan
|
||||
const atasanTable = $('#atasan-table').DataTable({
|
||||
order: [
|
||||
[1, 'asc']
|
||||
],
|
||||
columnDefs: [{
|
||||
targets: 0,
|
||||
orderable: false,
|
||||
searchable: false
|
||||
}],
|
||||
language: {
|
||||
emptyTable: 'Tidak ada data atasan'
|
||||
}
|
||||
});
|
||||
atasanTable.on('draw.dt', function() {
|
||||
renumber(atasanTable);
|
||||
}).draw(false);
|
||||
|
||||
// Tabel bawahan di modal (dibangun ulang setiap data berubah)
|
||||
let modalDataTable = null;
|
||||
|
||||
function destroyModalTable() {
|
||||
if (modalDataTable) {
|
||||
modalDataTable.destroy();
|
||||
modalDataTable = null;
|
||||
}
|
||||
}
|
||||
|
||||
function renderModalTable() {
|
||||
const page = modalDataTable ? modalDataTable.page() : 0;
|
||||
destroyModalTable();
|
||||
|
||||
const $body = $('#modalBawahanBody').empty();
|
||||
|
||||
currentBawahan.forEach(function(b, idx) {
|
||||
$body.append(
|
||||
@@ -485,6 +519,25 @@
|
||||
'</tr>'
|
||||
);
|
||||
});
|
||||
|
||||
modalDataTable = $('#modalBawahanTable').DataTable({
|
||||
autoWidth: false,
|
||||
order: [
|
||||
[2, 'asc']
|
||||
],
|
||||
columnDefs: [{
|
||||
targets: [0, 3],
|
||||
orderable: false,
|
||||
searchable: false
|
||||
}],
|
||||
language: {
|
||||
emptyTable: 'Belum ada bawahan yang ditugaskan'
|
||||
}
|
||||
});
|
||||
modalDataTable.on('draw.dt', function() {
|
||||
renumber(modalDataTable);
|
||||
});
|
||||
modalDataTable.page(Math.min(page, Math.max(modalDataTable.page.info().pages - 1, 0))).draw('page');
|
||||
}
|
||||
|
||||
function renderModalSelectOptions() {
|
||||
@@ -511,6 +564,7 @@
|
||||
function loadModalData(nip, nama) {
|
||||
currentNipAtasan = nip;
|
||||
$('#modalAtasanNama').text(nama);
|
||||
destroyModalTable();
|
||||
$('#modalBawahanBody').html('<tr><td colspan="4" class="text-center text-muted py-3">Memuat data...</td></tr>');
|
||||
currentBawahan = [];
|
||||
availablePegawais = [];
|
||||
@@ -531,6 +585,7 @@
|
||||
renderModalSelectOptions();
|
||||
},
|
||||
error: function() {
|
||||
destroyModalTable();
|
||||
$('#modalBawahanBody').html('<tr><td colspan="4" class="text-center text-danger py-3">Gagal memuat data</td></tr>');
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user