|
|
|
สอบถามเรื่องการลบข้อมูลบน modal เมื่อลบแล้วให้ Refesh ข้อมูลบน modal เลยf |
|
|
|
|
|
|
|
*ตอนนี้ดึงข้อมูลมาแสดงบน modal ได้แล้ว / ลบข้อมูลรายได้แล้ว เหลือแค่ให้ข้อมูลบน modal refesh ไปด้วยโดยไม่ต้องปิด modal ต้องเขียนยังไงครับ
Code table แสดงข้อมูล (PHP)
print("<table class=\"table table-sm table-bordered\" style=\"width:100%;\" align=\"center\">");
print("<thead class=\"bg-success text-white\" style=\"text-align:center;\">");
print("<tr>");
print("<td style=\"width:10%\">");
print("วันที่เข้าปฏิบัติงาน");
print("</td>");
print("<td style=\"width:10%\">");
print("ชื่อวิศวกร");
print("</td>");
print("<td style=\"width:10%\">");
print("ชื่อผู้คุมงาน");
print("</td>");
print("<td style=\"width:20%\">");
print("ชื่องาน");
print("</td>");
print("<td style=\"width:5%\">");
print("ใบขออนุญาต");
print("</td>");
print("<td style=\"width:5%\">");
print("ใบประเมิน");
print("</td>");
print("</tr>");
print("</thead>");
if (isset($_POST['company'])) {
$get_data = getlist("SELECT * FROM access_work where id_company='" . $_POST['company'] . "' ORDER BY id_work DESC");
} else {
$get_data = getlist("SELECT * FROM access_work where start_work='$date' ORDER BY id_work DESC");
}
for ($i = 0; $i < sizeof($get_data); $i++) {
print("<tbody>");
print("<tr class=\"border\">");
print("<td style=\"text-align:center;vertical-align: middle;\">");
print(printlongSlatethaiDate($get_data[$i]['start_work']));
print("</td>");
print("<td style=\"text-align:center;vertical-align: middle;\">");
print($get_data[$i]['engineer_name']);
print("</td>");
print("<td style=\"text-align:center;vertical-align: middle;\">");
$data = getlist("SELECT * FROM employees where id_peple='" . $get_data[$i]['shif_work'] . "'");
print($data[0]['peple_name']);
print("</td>");
print("<td style=\"text-align:center;vertical-align: middle;\">");
print($get_data[$i]['work_name']);
print("</td>");
print("<td style=\"text-align:center;vertical-align: middle;\">");
$link = "http://my-vngs.com/main/safety/print_acess_work.php?id_work=" . $get_data[$i]['id_work'];
print("<button type=\"button\" class=\"btn btn-success btn-sm estimate\" data-bs-toggle=\"modal\" id='" . $get_data[$i]['id_work'] . "' data-bs-target=\"#show_estimate\"><i class=\"bi bi-layout-text-window-reverse\"></i></button>");
print("</td>");
print("<td style=\"text-align:center;vertical-align: middle;\">");
$link = "http://my-vngs.com/main/safety/assessment.php?id_work=" . $get_data[$i]['id_work'];
print("<a href=\"$link\" target=\"blank\">ใบประมิน</a>");
print("</td>");
print("</tr>");
print("</tbody>");
}
print("</table>");
Code modal
<div class="modal fade" id="show_estimate" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header" >
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="exampleModal" >
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
show_acess_work.php
<?php
@session_start();
@ini_set('display_errors', '0');
include "../include/mySqlFunc.php";
query("USE safety");
$id_work = $_POST['id_work'];
if (isset($_POST['function']) && $_POST['function'] == 'delete_empwork') {
$id_delete = $_POST['id'];
query("DELETE FROM access_employee where id_access='$id_delete'");
echo json_encode(array('status' => '1', 'message' => 'Insert data successfully.'));
exit();
}
function nextPage()
{
print("</table>");
print("<div style=\”page-break-before:always;page-break-after:always;\”></div>");
}
$query_data = getlist("SELECT * FROM access_work where id_work='$id_work'");
print("<div class=\"header1\" style=\"border-bottom: 1px solid #adadad;width: 180mm;\">ใบขออนุญาตเข้าปฏิบัติงานผู้รับเหมา</div>");
print("<table border=\"0\" cellspacing = \"0\" cellpadding = \"0\" align = \"center\" valign = \"middle\" style=\"width:180mm;empty-cells: show;\">");
print("<tr>");
print("<td class=\"head1\">");
print("วันที่ปฏิบัติงาน <b>" . printlongSlatethaiDate($query_data[0]['start_work']) . "</b>");
print("</td>");
print("<td class=\"head1 \">");
print("<t style=\"margin-left:140px;\">สิ้นสุด <b>" . printlongSlatethaiDate($query_data[0]['end_work']) . "</b></t>");
print("</td>");
print("</tr>");
print("<tr>");
print("<td class=\"head1\">");
print("ชื่อวิศวกรเจ้าของงาน <b>" . $query_data[0]['engineer_name'] . "</b>");
print("</td>");
print("<td class=\"head1\">");
print("<t style=\"margin-left:140px;\">เบอร์ติดต่อ <b>" . $query_data[0]['engineer_phone'] . "</b></t>");
print("</td>");
print("</tr>");
print("</tr>");
print("<tr>");
print("<td colspan=\"4\" class=\"head1\">");
$company = getlist("SELECT * FROM company where id_company='" . $query_data[0]['id_company'] . "'");
print("ชื่อบริษัทผู้รับเหมา <b>" . $company[0]['company_name'] . "</b>");
print("</td>");
print("</tr>");
print("<tr>");
print("<td class=\"head1\">");
$shif = getlist("SELECT * FROM employees where id_peple='" . $query_data[0]['shif_work'] . "'");
print("ชื่อผู้ควบคุมงาน <b>" . $shif[0]['peple_name'] . "</b>");
print("</td>");
print("<td class=\"head1\">");
print("<t style=\"margin-left:140px;\">เบอร์ติดต่อ <b>" . $query_data[0]['shif_phone'] . "</b></t>");
print("</td>");
print("</tr>");
print("</tr>");
print("<tr>");
print("<td class=\"head1\">");
print("ชื่องาน <b>" . $query_data[0]['work_name'] . "</b>");
print("</td>");
print("<td class=\"head1\" > ");
$emp = getlist("SELECT * FROM access_employee where id_work='$id_work'");
print("<t style=\"margin-left:140px;\">จำนวนผู้ปฏิบัติงาน <b>" . sizeof($emp) . " คน</b></t>");
print("</td>");
print("</tr>");
print("</table>");
print("<table border=\"0\" cellspacing = \"0\" cellpadding = \"0\" align = \"center\" valign = \"middle\" style=\"width:180mm;empty-cells: show;\">");
print("<tr class=\"body_report\" style=\"border:none !important;\">");
print("<td colspan=\"4\">");
print("<b>รายชื่อผู้ปฏิบัติงานที่เข้ามาทำงานภายในบริษัท ดังนี้");
print("</td>");
print("<td id=\"non-printable\">");
print("<a onclick = \"window.open('edit_report_access_work.php?id_work=$id_work' , '','nenuber=no,toorlbar=no,location=no,scrollbars=no, status=no,resizable=no,width=750,height=600,top=45 ,left=250') \" style=\"cursor:pointer;color:#43ad04;\"><img src=\"images/edit.png\" width=\"50\" height=\"30\" ></a> ");
print("</td>");
print("</tr>");
print("<tr style=\"text-align:center;font-weight:bold;\" class=\"body_report border\">");
print("<td style=\"width:10mm;\" rowspan=\"2\">");
print("ลำดับ");
print("</td>");
print("<td style=\"width:95mm;\" rowspan=\"2\">");
print("ชื่อ-นามสกุล");
print("</td>");
print("<td style=\"width:30mm;\" rowspan=\"2\">");
print("ลายมือชื่อ");
print("</td>");
print("<td style=\"width:40mm;\" colspan=\"2\" >");
print("การอบรม");
print("</td>");
print("</tr>");
print("<tr style=\"text-align:center;font-weight:bold;\" class=\"body_report border\">");
print("<td style=\"width:20mm;\" >");
print("ผ่านการอบรม");
print("</td>");
print("<td style=\"width:20mm;\">");
print("ไม่ผ่านการอบรม");
print("</td>");
print("</tr>");
print("<br>");
$count = 15;
for ($i = 0; $i < sizeof($emp); $i++) {
print("<tr class=\"body_report border\">");
print("<td style=\"text-align:center;\">");
print($i + 1);
print("</td>");
print("<td>");
$employee = getlist("SELECT * FROM employees where id_peple='" . $emp[$i]['id_employee'] . "'");
print("<t style=\"margin-left:30px;\">" . $employee[0]['peple_name'] . "</t>");
print("</td>");
print("<td>");
print(" ");
print("</td>");
print("<td>");
print(" ");
print("</td>");
print("<td>");
print(" ");
print("</td>");
print("<td id=\"non-printable\">");
print("<a type=\"button\" title=\"ลบข้อมูล\" action=\"select.php\" value=\"view\" class=\"btn btn-danger btn-sm text-white delete_empwork\" id=" . $emp[$i]['id_access'] . " name=\"" . $employee[0]['peple_name'] . "\" data-toggle=\"modal\" data-target=\"#update_status\" ><i class=\"bi bi-trash3\"></i></a>");
print("</td>");
print("</tr>");
}
for ($k = $i; $k < $count; $k++) {
print("<tr class=\"body_report border\">");
print("<td style=\"text-align:center;\">");
print($k + 1);
print("</td>");
print("<td>");
print(" ");
print("</td>");
print("<td>");
print(" ");
print("</td>");
print("<td>");
print(" ");
print("</td>");
print("<td>");
print(" ");
print("</td>");
print("</tr>");
}
print("</table>");
print("<table border=\"0\" cellspacing = \"0\" cellpadding = \"0\" align = \"center\" valign = \"middle\" style=\"width:180mm;empty-cells: show;margin-top:50px;\">");
print("<tr >");
print("<td class=\"head1\" style=\"text-align:center;\">");
print("ลงชื่อ............................................ผู้อบรม<br>");
print("(.....................................................)<br>");
print("วันที่............./............./.............)");
print("</td>");
print("<td class=\"head1 \" style=\"text-align:center;\">");
print("ลงชื่อ...................................................วิศวกร/เจ้าของงาน<br>");
print("(.....................................................)<br>");
print("วันที่............./............./.............)");
print("</td>");
print("</tr>");
print("<tr>");
print("<td>");
print("<div class=\"divFooter\" style=\"border-top: 1px solid #adadad;text-align: center;width: 180mm;font-size:11px;\">
บริษัท วนชัย กรุ๊ป จำกัด(มหาชน) 112 หมู่ 1 นิคมอุตสาหกรรมแก่งคอย ตำบลบ้านธาตุ อำเภอแก่งคอย จังหวัดสระบุรี 036-241333-41</div>");
print("</td>");
print("</tr>");
print("</table>");
?>
Code (JavaScript)
//แสดงข้อมูลบน modal
$(document).on('click', '.estimate', function(){
//$('#dataModal').modal();
var modalContent = $('#show_estimate .modal-content');
var id_work = $(this).attr("id");
$.ajax({
url:"show_acess_work.php",
method:"POST",
data:{id_work:id_work},
success:function(data){
$('#exampleModal').html(data);
$('#show_estimate').modal('show');
}
});
});
//ลบข้อมูล
$('.delete_empwork').click(function(){
var id=$(this).attr('id');
var name_emp=$(this).attr('name');
var action = $(this).attr('action');
//alert(action);
Swal.fire({
title: 'คุณแน่ใจไหม?',
text: "คุณต้องการลบ \n"+name_emp+"",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#28a745',
cancelButtonColor: '#dc3545',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "show_acess_work.php",
type: "POST",
data: {id:id,function:"delete_empwork"},
dataType: "html",
//dataType: "html",
success: function(reponse) {
console.log(response)
}
})
}
})
});
Tag : PHP, HTML, JavaScript, Ajax, jQuery, Bootstrap Framework
|
|
|
|
|
|
Date :
2023-05-09 15:31:24 |
By :
benlovehi5 |
View :
397 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ใน js ได้เลยครับ concept คือดึง data ใหม่หลังลบสำเร็จก็ได้คครับ
Code (JavaScript)
function fetchData(){
$.ajax({
url:"show_acess_work.php",
method:"POST",
data:{id_work:id_work},
success:function(data){
return data
}
});
}
$(document).on('click', '.estimate', function(){
//$('#dataModal').modal();
var modalContent = $('#show_estimate .modal-content');
var id_work = $(this).attr("id");
var data = fetchData();
$('#exampleModal').html(data);
$('#show_estimate').modal('show');
});
//ลบข้อมูล
$('.delete_empwork').click(function(){
var id=$(this).attr('id');
var name_emp=$(this).attr('name');
var action = $(this).attr('action');
//alert(action);
Swal.fire({
title: 'คุณแน่ใจไหม?',
text: "คุณต้องการลบ \n"+name_emp+"",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#28a745',
cancelButtonColor: '#dc3545',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "show_acess_work.php",
type: "POST",
data: {id:id,function:"delete_empwork"},
dataType: "html",
//dataType: "html",
success: function(reponse) {
$('#exampleModal').html('');
var data = fetchData();
$('#exampleModal').html(data);
}
})
}
})
});
ประมาณนี้ครับ
จริงๆถ้าเอา เนียนๆใช้ jquery จับเอา event click row นั้น ถ้าลบสำเร็จ ก็แค่ remove html row นั้นออกไป โดยไม่ต้อง reload หรอ fetch data ใหม่
|
|
|
|
|
Date :
2023-06-19 17:12:00 |
By :
mongkon.k |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|