Compare commits

...

2 Commits

Author SHA1 Message Date
65f4657d4d Persiapan untuk fitur Create, Update, dan Delete 2025-06-10 11:24:02 +07:00
f2975a0089 Fetch data dari API 2025-06-10 11:14:55 +07:00
2 changed files with 48 additions and 3 deletions

View File

@ -4,12 +4,17 @@
<link rel="stylesheet" href="//cdn.datatables.net/2.3.2/css/dataTables.dataTables.min.css">
</head>
<body>
<input type="text" placeholder="Name" />
<input type="text" placeholder="Phone" />
<button>Create</button>
<hr>
<table id="table-list">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Phone</th>
<th>Act</th>
</tr>
</thead>
@ -20,9 +25,7 @@
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="//cdn.datatables.net/2.3.2/js/dataTables.min.js"></script>
<script src="js/carrack.js"></script>
<script>
var table = $('#table-list').DataTable({})
</script>
<script src="js/data.js"></script>
</body>
</html>

42
js/data.js Normal file
View File

@ -0,0 +1,42 @@
var table = $('#table-list').DataTable({
"ajax": {
"url": "http://localhost:11000/api/read",
"type": "POST",
"dataSrc": "data",
"contentType": "application/json",
"data": function(d) {
// Customize the data payload sent in the POST request
return JSON.stringify({});
},
"error": function (xhr, error, thrown) {
console.error('Error fetching data:', thrown);
console.error('Response:', xhr.responseText);
}
},
"columns": [
{
"data": "id",
"render": function(data, type, row) {
return data;
}
},
{
"data": "name",
"render": function(data, type, row) {
return data;
}
},
{
"data": "phone",
"render": function(data, type, row) {
return data;
}
},
{
"data": null,
"render": function(data, type, row) {
return `<button>Update</button> <button>Delete</button>`;
}
},
],
})