in this when i move the table rows SrNo gets reordered the same order i need in order field and need to update it to db
HOW DO I PASS the sr no from view to controller
<script type="text/javascript">
$(document).ready(function () {
$('#myDataTable').dataTable().rowReordering({ sURL: "/details/UpdateOrder" });
rowReorder: true
});
</script>
<table id="myDataTable">
<thead>
<tr>
<th> details </th>
<th>Index</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@{int srNo = 0;}
@foreach (var item in Model)
{
<tr class="gradeX" id="@item.DetailID">
<td > @(srNo += 1)
</td>
<td> @item.Details </td>
<td>@item.OrderIndex</td>
<td><a href="@Url.Action(" Edit", new { @id = item.DetailID })">Edit </a></td>
Details</a></td>
</tr>
}
</tbody>
</table>
referring
https://www.codeproject.com/Articles/331986/Table-Row-Drag-and-Drop-in-ASP-NET-MVC-JQuery-Data
<link href="~/Content/dataTables/demo_table.css" rel="stylesheet" type="text/css" />
<script src="~/ScriptsjQuery-1.5.1.min.js" type="text/javascript"></script>
<script src="~/Scripts/jQuery-ui-1.8.11.min.js" type="text/javascript"></script>
<script src="~/Scripts/jQuery.dataTables.min.js" type="text/javascript"></script>
<script src="~/Scripts/jQuery.dataTables.rowReordering.js" type="text/javascript"></script>
[HttpPost]
public JsonResult UpdateOrder(int id, int fromPosition, int toPosition, string direction)
{
int rowNo = 0;
if (direction == "back")
{
var movedrecords = db.dbDetails .Where(c => (toPosition <= c.OrderIndex && c.OrderIndex <= fromPosition))
.ToList();
foreach (var order in movedrecords)
{
order.OrderIndex++;
}
}
else
{
var movedrecords = db.dbDetails
.Where(c => (toPosition <= c.OrderIndex && c.OrderIndex <= fromPosition))
.ToList();
foreach (var order in movedrecords)
{
order.OrderIndex--;
}
}
var records = db.dbDetails .Where(c => c.DetailID == id).FirstOrDefault();
records.OrderIndex = toPosition;
db.Entry(records).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
return Json(true);
}