在php生成的表中,我使用拖放行来更改排序。 (第一张图片,第二张图片....)
如果我首先删除第4行,它将是第一行,但是我删除的行,它保持为第4行,行不会重新编号。
如何重新编号行,并将索引放在名为sorrend_hidden的隐藏输入中?
<table class="table table-hover table-bordered list" id="table_2">
<thead>
<tr>
<td style="width: 1px; text-align: center;"><input type="checkbox" class="checkAllCheckboxes" /></td>
<td style="text-align: center;">ID</td>
<td class="left">Kép</td>
<td class="left">Megnevezés</td>
<td style="text-align: center;">Sorrend</td>
<td style="text-align: center;">Státusz</td>
<td class="right">Műveletek</td>
</tr>
</thead>
<tbody>
<tr id="sor24">
<td class="left"><input class="table_row_checkbox" type="checkbox" name="selectedRows[]" value="24" /></td>
<td style="text-align: center;">24</td>
<td class="left"><img width="200" src="images/homepage_slideshow/89-FIFA_17_B4jlEln.jpg" class="img-responsive" /></td>
<td class="left"></td>
<input type="hidden" value="" name="sorrend_hidden" />
<td style="text-align: center;">2</td>
<td style="text-align: center;">Intaktív</td>
<td class="right">
<a href="cms/slideshow-szerkesztes.php?id=24"><span class="btn btn-sm button"><span class="glyphicon glyphicon-pencil"></span></span></a>
<a id="24" href="#" class="deleteLink"><span class="btn btn-sm btn-danger "><span class="glyphicon glyphicon-remove"></span></span></a>
</td>
</tr>
<tr id="sor31">
<td class="left"><input class="table_row_checkbox" type="checkbox" name="selectedRows[]" value="31" /></td>
<td style="text-align: center;">31</td>
<td class="left"><img width="200" src="images/homepage_slideshow/503-WatchDogs2_FarCrayPrimal_1_.jpg" class="img-responsive" /></td>
<td class="left"></td>
<input type="hidden" value="" name="sorrend_hidden" />
<td style="text-align: center;">2</td>
<td style="text-align: center;">Aktív</td>
<td class="right">
<a href="cms/slideshow-szerkesztes.php?id=31"><span class="btn btn-sm button"><span class="glyphicon glyphicon-pencil"></span></span></a>
<a id="31" href="#" class="deleteLink"><span class="btn btn-sm btn-danger "><span class="glyphicon glyphicon-remove"></span></span></a>
</td>
</tr>
<tr id="sor30">
<td class="left"><input class="table_row_checkbox" type="checkbox" name="selectedRows[]" value="30" /></td>
<td style="text-align: center;">30</td>
<td class="left"><img width="200" src="images/homepage_slideshow/324-DeadRising4_megjelent.jpg" class="img-responsive" /></td>
<td class="left"></td>
<input type="hidden" value="" name="sorrend_hidden" />
<td style="text-align: center;">3</td>
<td style="text-align: center;">Aktív</td>
<td class="right">
<a href="cms/slideshow-szerkesztes.php?id=30"><span class="btn btn-sm button"><span class="glyphicon glyphicon-pencil"></span></span></a>
<a id="30" href="#" class="deleteLink"><span class="btn btn-sm btn-danger "><span class="glyphicon glyphicon-remove"></span></span></a>
</td>
</tr>
<tr id="sor32">
<td class="left"><input class="table_row_checkbox" type="checkbox" name="selectedRows[]" value="32" /></td>
<td style="text-align: center;">32</td>
<td class="left"><img width="200" src="images/homepage_slideshow/492-PS-VR_.jpg" class="img-responsive" /></td>
<td class="left"></td>
<input type="hidden" value="" name="sorrend_hidden" />
<td style="text-align: center;">4</td>
<td style="text-align: center;">Aktív</td>
<td class="right">
<a href="cms/slideshow-szerkesztes.php?id=32"><span class="btn btn-sm button"><span class="glyphicon glyphicon-pencil"></span></span></a>
<a id="32" href="#" class="deleteLink"><span class="btn btn-sm btn-danger "><span class="glyphicon glyphicon-remove"></span></span></a>
</td>
</tr>
<tr id="sor23">
<td class="left"><input class="table_row_checkbox" type="checkbox" name="selectedRows[]" value="23" /></td>
<td style="text-align: center;">23</td>
<td class="left"><img width="200" src="images/homepage_slideshow/90-konzolkiraly_sl_1467362325.jpg" class="img-responsive" /></td>
<td class="left"></td>
<input type="hidden" value="" name="sorrend_hidden" />
<td style="text-align: center;">5</td>
<td style="text-align: center;">Intaktív</td>
<td class="right">
<a href="cms/slideshow-szerkesztes.php?id=23"><span class="btn btn-sm button"><span class="glyphicon glyphicon-pencil"></span></span></a>
<a id="23" href="#" class="deleteLink"><span class="btn btn-sm btn-danger "><span class="glyphicon glyphicon-remove"></span></span></a>
</td>
</tr>
</tbody>
</table>
Jquery:
$("#table_2").tableDnD(
{
onDrop: function(table, row)
{
var rows = table.tBodies[0].rows;
var RowID = row.id.substr(3);
var RowIndex = $(row).index() + 1;
// name = sorrend_hidden
$.ajax({
data: { RowID:RowID, RowIndex:RowIndex },
type: 'POST',
url: 'files/update_slide_index.php',
success: function(data)
{
var result = $.trim(data);
$('#newsletterResult').html(result);
$('#newsletterModal').modal('show');
},
complete: function()
{
setTimeout(function()
{
location.reload();
}, 3000 );
}
});
}
});
Sql update:
<?php
include_once("../../files/connect.php");
if(isset($_POST['RowID']))
{
$RowID = intval($_POST['RowID']);
$RowIndex = intval($_POST['RowIndex']);
$sql = "UPDATE slideshow SET slide_sorrend = '$RowIndex' WHERE slide_id = '$RowID'";
/*if(mysqli_query($kapcs, $sql))
{
mysqli_query($kapcs, "UPDATE slideshow SET slide_sorrend = slide_sorrend + 1 WHERE slide_id != '$RowID'") or die(mysqli_error($kapcs));
}
else
{
die(mysqli_error($kapcs));
}*/
echo 'A kép sorrendje sikeresen megváltozott.';
}
else
{
echo 'Nincs ID';
}
?>
答案 0 :(得分:0)
几个月前我遇到过类似的问题。我最终使用了jQuery UI中包含的可排序功能。