简体   繁体   English

数据表重新排序问题

[英]Datatable reorder issue

I'm having an issue with the following code. 我的以下代码有问题。 What I'm trying to do is to populate a modal form with data from the row on which you pressed the edit button. 我想要做的是用您按下编辑按钮的行中的数据填充模式表格。 The script works fine until I try to reorder the table: when the table is reordered the script is getting the information of the pre-reordered table. 在尝试对表进行重新排序之前,脚本可以正常工作:对表进行重新排序时,脚本会获取已预排序的表的信息。

This is the script that get called when the edit button get clicked: 这是单击编辑按钮时调用的脚本:

 $(document).ready( function () { //create datatable //declaring a variable without var makes it global table_movimenti = $('#movimenti').DataTable(); $('#movimenti table tbody tr td').on('click', function () { $("#transaction_ID").val($(this).find("td:eq(6)").attr('id')); $("#data_cont").val($(this).find("td:eq(0)").text()); $("#data_valuta").val($(this).find("td:eq(1)").text()); $("#importo").val($(this).find("td:eq(2)").text()); $("#divisa").val($(this).find("td:eq(3)").text()); $("#causale").val($(this).find("td:eq(4)").text()); var categoria=$.trim($(this).find("td:eq(5)").text()); $("#categoria option").each(function() { if($(this).text() == categoria){ //$(this).prop("selected", true); $(this).attr("selected", "selected"); return; } }); }); 

This is the table: 这是表:

 <?php echo "<table id='movimenti' class='table table-bordered table-striped table no-margin'>"; echo "<thead>"; echo "<tr>"; echo "<th>Data contabile</th>"; echo "<th>Data valuta</th>"; echo "<th>Importo</th>"; echo "<th>Divisa</th>"; echo "<th>Causale</th>"; echo "<th>Categoria</th>"; echo "<th>Edit</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; while($row = mysqli_fetch_array($result)){ echo "<tr class='table_row'>"; echo " <td>" . $row['Data_cont'] . "</td>"; echo " <td>" . $row['Data_valuta'] . "</td>"; echo " <td>" . $row['Importo'] . "</td>"; echo " <td>" . $row['Divisa'] . "</td>"; echo " <td>" . $row['Causale'] . "</td>"; echo " <td>"; foreach ($categories as $value){ if ($value['ID'] == $row['Categoria']){ echo " <span class='label label-success'>"; echo "". $value['Descrizione'] .""; echo "<input type='text' class='label label-success' id='categoria' name='categoria' value='". $value['Descrizione'] ."'/>"; echo "</span></td>"; } } 

In the end I've completely change the approach and now I'm building my table using ajax option in datatable. 最后,我完全改变了方法,现在我在datatable中使用ajax选项构建表。 In this way I'm able to retrieve all the data in the row using the same ajax option. 这样,我可以使用相同的ajax选项检索该行中的所有数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM