document.addEventListener("DOMContentLoaded", function () { loadListSubDistrict(); $(document).on("click", ".btn-edit-sub-district", function (event) { let button = event.target; let id = $(this).data("id"); let sub_district = button.getAttribute("data-sub-district"); let latitude = button.getAttribute("data-latitude"); let longitude = button.getAttribute("data-longitude"); $('[name="subDistrictId"]').val(id); $('[name="subDistrict"]').val(sub_district); $('[name="latitude"]').val(latitude); $('[name="longitude"').val(longitude); }); $(document).on("click", "#btn-hapus", function () { let id = $(this).data("id"); Swal.fire({ html: '

Apakah anda benar ?

Anda benar, akan menghapus data kecamatan ?

', showCancelButton: !0, confirmButtonClass: "btn btn-primary w-xs me-2 mb-1", confirmButtonText: "Ya, hapus!", cancelButtonClass: "btn btn-danger w-xs mb-1", buttonsStyling: !1, showCloseButton: !0, }).then((result) => { if (result.isConfirmed) { window.location.href = "/list-data-kecamatan/deleteSubDistrict/" + id; } }); }); }); let gridInstance; function loadListSubDistrict() { const tableContainerListSubDistrict = document.getElementById( "table-list-sub-district" ); if (tableContainerListSubDistrict) { tableContainerListSubDistrict.innerHTML = ""; } $.ajax({ url: `/list-data-kecamatan/getListSubDistrict`, type: "GET", dataType: "json", success: function (data) { const tableDataListSubDistrict = data["listSubDistrict"].map( (item, index) => [ index + 1, item["sub_district"], parseFloat(item["latitude"]).toFixed(5), parseFloat(item["longitude"]).toFixed(5), gridjs.html( ` ` ), ] ); if (gridInstance) { gridInstance .updateConfig({ data: tableDataListSubDistrict, }) .forceRender(); } else { const isMobile = window.innerWidth < 768; const columns = isMobile ? ["No", "Kecamatan", "Latitude", "longitude", "Aksi"] : [ { name: "No", width: "10%" }, { name: "Kecamatan", width: "30%" }, { name: "Latitude", width: "20%" }, { name: "longitude", width: "20%" }, { name: "Aksi", width: "20%" }, ]; gridInstance = new gridjs.Grid({ columns: columns, data: tableDataListSubDistrict, search: true, sort: true, pagination: { limit: 5, }, }).render(tableContainerListSubDistrict); } }, }); }