style: implement plugin datatable & sweetalert
parent
d40353dcde
commit
36530d3a54
|
|
@ -3,11 +3,41 @@
|
||||||
namespace BankSampahApp.Areas.Dinas.Controllers
|
namespace BankSampahApp.Areas.Dinas.Controllers
|
||||||
{
|
{
|
||||||
[Area("Dinas")]
|
[Area("Dinas")]
|
||||||
|
[Route("Dinas/[controller]/[action]")]
|
||||||
public class JenisBankSampahController : Controller
|
public class JenisBankSampahController : Controller
|
||||||
{
|
{
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Table()
|
||||||
|
{
|
||||||
|
var data = new[]
|
||||||
|
{
|
||||||
|
new {
|
||||||
|
nama = "BSI",
|
||||||
|
aksi = "<div class=\"flex gap-2\">" +
|
||||||
|
"<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>" +
|
||||||
|
"<a href=\"#\" class=\"btn btn-circle btn-error delete text-white btn-sm\"><i class=\"ph ph-trash\"></i></a>" +
|
||||||
|
"</div>",
|
||||||
|
},
|
||||||
|
new {
|
||||||
|
nama = "BSU",
|
||||||
|
aksi = "<div class=\"flex gap-2\">" +
|
||||||
|
"<a href=\"#\" class=\"btn btn-circle btn-warning text-white btn-sm\"><i class=\"ph ph-note-pencil\"></i></a>" +
|
||||||
|
"<a href=\"#\" class=\"btn btn-circle btn-error delete text-white btn-sm\"><i class=\"ph ph-trash\"></i></a>" +
|
||||||
|
"</div>",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
var response = new
|
||||||
|
{
|
||||||
|
data = data
|
||||||
|
};
|
||||||
|
|
||||||
|
return Json(response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,45 +21,59 @@
|
||||||
|
|
||||||
<div class="card bg-white">
|
<div class="card bg-white">
|
||||||
<div class="card-body p-2">
|
<div class="card-body p-2">
|
||||||
<partial name="~/Areas/Shared/Components/Table/_Control.cshtml" />
|
<table class="table-zebra table" id="example">
|
||||||
<div class="overflow-x-auto">
|
<!-- head -->
|
||||||
<table class="table-zebra table">
|
<thead>
|
||||||
<!-- head -->
|
<tr>
|
||||||
<thead>
|
<th class="w-[5%]">No</th>
|
||||||
<tr>
|
<th class="w-[85%]">Nama Jenis Bank Sampah</th>
|
||||||
<th class="w-[5%]">No</th>
|
<th class="w-[10%]">Aksi</th>
|
||||||
<th class="w-[85%]">Nama Jenis Bank Sampah</th>
|
</tr>
|
||||||
<th class="w-[10%]">Aksi</th>
|
</thead>
|
||||||
</tr>
|
<tbody></tbody>
|
||||||
</thead>
|
</table>
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th>1</th>
|
|
||||||
<td>BSI</td>
|
|
||||||
<td>
|
|
||||||
<a href="#" class="btn btn-circle btn-warning btn-sm text-white">
|
|
||||||
<i class="ph ph-note-pencil"></i>
|
|
||||||
</a>
|
|
||||||
<a href="#" class="btn btn-circle btn-error btn-sm text-white">
|
|
||||||
<i class="ph ph-trash"></i>
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>2</th>
|
|
||||||
<td>BSU</td>
|
|
||||||
<td>
|
|
||||||
<a href="#" class="btn btn-circle btn-warning btn-sm text-white">
|
|
||||||
<i class="ph ph-note-pencil"></i>
|
|
||||||
</a>
|
|
||||||
<a href="#" class="btn btn-circle btn-error btn-sm text-white">
|
|
||||||
<i class="ph ph-trash"></i>
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<partial name="~/Areas/Shared/Components/Table/_Pagination.cshtml" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||||
|
<script src="https://cdn.datatables.net/2.3.4/js/dataTables.js"></script>
|
||||||
|
<script src="/plugins/datatables/dataTables.tailwindcss.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var table;
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
table = new DataTable('#example', {
|
||||||
|
ajax: '/Dinas/JenisBankSampah/Table',
|
||||||
|
scrollX: true,
|
||||||
|
autoWidth: false,
|
||||||
|
initComplete: function () {
|
||||||
|
$('div.dt-scroll-body thead').css('visibility', 'collapse');
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{ data: null, render: (d, t, r, m) => m.row + 1, orderable: false, searchable: false },
|
||||||
|
{ data: 'nama' },
|
||||||
|
{ data: 'aksi' },
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
table.on("click", ".delete", function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
let url = $(this).data("url");
|
||||||
|
swal.fire({
|
||||||
|
title: "Apakah anda yakin?",
|
||||||
|
text: "Data yang dihapus tidak dapat dikembalikan lagi",
|
||||||
|
icon: "question",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "Ya, Hapus",
|
||||||
|
cancelButtonText: "Batal",
|
||||||
|
buttonsStyling: false,
|
||||||
|
customClass: {
|
||||||
|
confirmButton: "btn btn-error text-white",
|
||||||
|
cancelButton: "btn btn-link no-underline text-gray-500",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue