Compare commits

..

2 Commits
master ... pagi

Author SHA1 Message Date
52afee5e25 Bikin fitur Update dan Delete pada tiap row 2025-06-17 11:05:03 +07:00
7c00802a77 Bikin form Add 2025-06-17 10:46:25 +07:00
2 changed files with 41 additions and 32 deletions

View File

@ -6,7 +6,7 @@
<body>
<input id="form-add-name" type="text" placeholder="Name" />
<input id="form-add-phone" type="text" placeholder="Phone" />
<button type="button" onclick="buttonAdd()">Create</button>
<button id="button-add" type="button" onclick="buttonAdd()">Create</button>
<hr>
<table id="table-list">
<thead>

View File

@ -27,13 +27,13 @@ var table = $('#table-list').DataTable({
{
"data": "name",
"render": function(data, type, row) {
return `<input id="form-edit-name-${row.id}" value="${data}">`;
return `<input id="form-edit-name-${row.id}" type="text" value="${data}">`;
}
},
{
"data": "phone",
"render": function(data, type, row) {
return `<input id="form-edit-phone-${row.id}" value="${data}">`;
return `<input id="form-edit-phone-${row.id}" type="text" value="${data}">`;
}
},
{
@ -52,10 +52,13 @@ function buttonAdd() {
var payload = {
"name" : name,
"phone" : phone
}
};
sendHttpRequest(url, "POST", payload, function (error, response) {
if (error) console.error(`Error: ${error}`);
else table.ajax.reload(null, false);
if (error) console.error("Error:", error);
else {
table.ajax.reload(null, false); // false means keep the current page
console.log("JSON Response:", response);
}
}, "application/json");
}
@ -67,22 +70,28 @@ function buttonEdit(key) {
"key" : key,
"name" : name,
"phone" : phone
}
};
sendHttpRequest(url, "POST", payload, function (error, response) {
if (error) console.error(`Error: ${error}`);
else table.ajax.reload(null, false);
if (error) console.error("Error:", error);
else {
table.ajax.reload(null, false); // false means keep the current page
console.log("JSON Response:", response);
}
}, "application/json");
alert("Data berhasil dirubah");
alert("Data telah di Update");
}
function buttonRemove(key){
var url = "http://localhost:11000/api/delete";
var payload = {
"key" : key
}
};
sendHttpRequest(url, "POST", payload, function (error, response) {
if (error) console.error(`Error: ${error}`);
else table.ajax.reload(null, false);
}, "application/json");
alert("Data berhasil dihapus, permanent, selamanya!");
if (error) console.error("Error:", error);
else {
table.ajax.reload(null, false); // false means keep the current page
console.log("JSON Response:", response);
}
}, "application/json");
alert("Data telah di Hapus Selamanya");
}