数据表重新排序问题



我在使用以下代码时遇到问题。我正在尝试做的是用您按下编辑按钮的行中的数据填充模态表单。 在我尝试对表重新排序之前,脚本工作正常:当表重新排序时,脚本将获取预先重新排序的表的信息。

这是单击编辑按钮时调用的脚本:

$(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;
}
});
});

下表如下:

<?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>";
		}
}

最后,我已经完全改变了方法,现在我正在使用数据表中的ajax选项构建我的表。 通过这种方式,我能够使用相同的 ajax 选项检索行中的所有数据。

最新更新