Fix: Pagination DataTables pada Halaman Unduhan Tidak Berfungsi - #1722
Open
pandigresik wants to merge 2 commits into
Open
Fix: Pagination DataTables pada Halaman Unduhan Tidak Berfungsi#1722pandigresik wants to merge 2 commits into
pandigresik wants to merge 2 commits into
Conversation
Contributor
|
🔄 AI PR Review sedang antri di server...
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Halaman Unduhan (Dokumen, Prosedur, Regulasi) menggunakan DataTables dengan
serverSide: falsenamun API endpoint mengembalikan data secara server-side paginated. Akibatnya:recordsTotal/recordsFilteredtidak diset dari response.Perbaikan dilakukan dengan mengubah
serverSide: false→serverSide: truedan menggunakandataSrcsebagai callback function untuk memetakanmeta.pagination.totalkerecordsTotal/recordsFilteredyang dibaca DataTables.Changes
themes/opendk/default/resources/views/pages/unduhan/form-dokumen.blade.phpserverSide: false→serverSide: truedataSrc: 'data'→dataSrc: function(json) { ... return json.data; }untuk menyuntikkanrecordsTotal/recordsFiltereddarijson.meta.pagination.totalpageLength: 10danlengthMenu: [5, 10, 25, 50, 100]themes/opendk/default/resources/views/pages/unduhan/prosedur.blade.phpthemes/opendk/default/resources/views/pages/unduhan/regulasi.blade.phpReason
API JSON:API (
spatie/laravel-json-api-paginate) mengembalikanmeta.pagination.totaluntuk total record, namun DataTables denganserverSide: falsemengabaikan dropdown length dan tidak bisa membaca metadata pagination. DenganserverSide: true, DataTables mengirimpage[number]danpage[size]ke API dan membacarecordsTotal/recordsFiltereddari response JSON — namun hanya jika nilainya diset di objek response, bukan di config. ПоэтомуdataSrcsebagai callback digunakan untuk menyuntikkan nilai tersebut sebelum DataTables memproses response.Impact
Related Issue
Testing Checklist
/unduhan/form-dokumen— ubah dropdown "Tampilkan 10 data" ke 5/25/50/100, pastikan pagination dan jumlah record berubah sesuai/unduhan/prosedur— uji hal yang sama/unduhan/regulasi— uji hal yang samanpm run test:browserjika tersediaTechnical Details
Struktur Response API
API mengembalikan JSON:API format dengan
meta.pagination:{ "data": [...], "meta": { "pagination": { "total": 50, "count": 10, "per_page": 10, "current_page": 1, "total_pages": 5 } } }Mengapa
dataSrcsebagai callback?DataTables
serverSide: truemembacarecordsTotal/recordsFiltereddari response JSON (bukan dari config). DengandataSrcsebagai callback, kita menyuntikkan nilai tersebut ke objek JSON sebelum DataTables memprosesnya:Breaking Changes
Tidak ada. Perubahan hanya pada sisi view (Blade) dan kompatibel dengan API yang sudah ada.
Video
simplescreenrecorder-2026-09-02_14.38.33.mp4
simplescreenrecorder-2026-09-02_14.46.11.mp4