簡體   English   中英

Laravel 如何使用按鈕將數據從表移動到另一個

[英]Laravel how to move data from table to another using button

有什么簡單的方法可以使用 id 將數據從一個表移動到另一個表? 我想使用 id 獲取第一個表中的所有信息,將其插入另一個表,然后使用 Laravel 從當前表中刪除它。

在我的 Html 表中。 例如,我有待處理的預訂表並且有一個操作按鈕“接受”,然后如果我單擊它,數據將 go 到已接受的預訂表。

請參考這張照片。 在此處輸入圖像描述

你可以使用sortablejs來解決問題

文檔中檢查這個例子

如果你正在使用數據表,那么你可以做類似的事情

 var table1 = $("#pending").DataTable(); var table2 = $("#reserved").DataTable(); $(document).on("click", "#pending.move", function () { var row = table1.row( $(this).parents('tr') ); var rowNode = row.node(); row.remove(); table2.row.add( rowNode ).draw(); }); $(document).on("click", "#reserved.move", function () { var row =table2.row( $(this).parents('tr') ); var rowNode = row.node(); row.remove(); table1.row.add( rowNode ).draw(); });
 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> <table id="pending" class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">action</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td><button type="button" class="btn btn-primary btn-sm move">move</button></td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td><button type="button" class="btn btn-primary btn-sm move">move</button></td> </tr> <tr> <th scope="row">3</th> <td>Larry</td> <td>the Bird</td> <td><button type="button" class="btn btn-primary btn-sm move">move</button></td> </tr> </tbody> </table> <table id="reserved" class="table mt-5"> <thead> <tr> <th scope="col">#</th> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">Action</th> </tr> </thead> <tbody> </tbody> </table> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.21/js/jquery.dataTables.min.js"></script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM