Penambahan Akses Laman Dosen dab perbaikan fix
This commit is contained in:
@@ -662,6 +662,63 @@ Alpine.data('satuTable', (config) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
/*
|
||||
* Tabel berformat SATU di atas baris yang sudah dirender server (x-satu.datatable): pencarian, jumlah data per halaman,
|
||||
* dan pager bekerja dengan menyembunyikan baris <tbody>, jadi sel berisi tautan, formulir, atau input tetap utuh dan
|
||||
* tetap terkirim bersama formulir pembungkusnya. Baris dengan sel colspan (keadaan kosong) tidak dihitung.
|
||||
*/
|
||||
Alpine.data('satuDom', (config = {}) => ({
|
||||
// Awalan dt: komponen ini bersarang di dalam x-data formulir lain, jadi nama tidak boleh menabrak (mis. total).
|
||||
dtQ: '',
|
||||
dtPer: config.per ?? 10,
|
||||
dtPage: 1,
|
||||
dtItems: [],
|
||||
|
||||
init() {
|
||||
this.dtItems = [...this.$root.querySelectorAll('tbody > tr')]
|
||||
.filter((tr) => !tr.querySelector('td[colspan]'))
|
||||
.map((el) => ({ el, text: el.textContent.toLowerCase().replace(/\s+/g, ' ') }));
|
||||
this.$watch('dtQ', () => this.dtReset());
|
||||
this.$watch('dtPer', () => this.dtReset());
|
||||
this.dtApply();
|
||||
},
|
||||
|
||||
get dtMatches() {
|
||||
const q = this.dtQ.trim().toLowerCase();
|
||||
return q ? this.dtItems.filter((item) => item.text.includes(q)) : this.dtItems;
|
||||
},
|
||||
|
||||
get dtTotal() {
|
||||
return this.dtMatches.length;
|
||||
},
|
||||
|
||||
get dtPages() {
|
||||
return Math.max(1, Math.ceil(this.dtTotal / this.dtPer));
|
||||
},
|
||||
|
||||
get dtWindow() {
|
||||
const start = Math.max(1, Math.min(this.dtPage - 2, this.dtPages - 4));
|
||||
return Array.from({ length: Math.min(5, this.dtPages) }, (_, i) => start + i);
|
||||
},
|
||||
|
||||
dtReset() {
|
||||
this.dtPage = 1;
|
||||
this.dtApply();
|
||||
},
|
||||
|
||||
dtGo(page) {
|
||||
this.dtPage = Math.min(Math.max(1, page), this.dtPages);
|
||||
this.dtApply();
|
||||
},
|
||||
|
||||
dtApply() {
|
||||
const visible = new Set(this.dtMatches.slice((this.dtPage - 1) * this.dtPer, this.dtPage * this.dtPer));
|
||||
this.dtItems.forEach((item) => {
|
||||
item.el.hidden = !visible.has(item);
|
||||
});
|
||||
},
|
||||
}));
|
||||
|
||||
/*
|
||||
* Laporan berdata asli: setiap perubahan parameter menjalankan laporan ke server (JSON) dan hasilnya tampil
|
||||
* berhalaman; kolom bisa berbeda per parameter, jadi tabel dirender dinamis. Tautan Unduh/Cetak memuat parameter
|
||||
|
||||
Reference in New Issue
Block a user