I have a jquery table with property set to sortable( I can drag and drop rows),
<script type="text/javascript">
$(function () {
$("#tblLookup1 tbody").sortable({
items: 'tr',
cursor: 'pointer',
axis: 'y',
dropOnEmpty: false,
start: function (e, ui) {
ui.item.addClass("selected");
},
stop: function (e, ui) {
$("#tblLookup1 tbody tr").each((idx, tr) => {
$("td:nth-child(4)", tr).text(idx+1);
});
ui.item.removeClass("selected");
},
receive: function (e, ui) {
$(this).find("tbody").append(ui.item);
}
});
});
Now after sorting a column with the name preference gets updated, 1st row will have preference value=1, 2nd row =2 and so on...
Now these values are available until I refresh the page. So as to make permanent changes I want to update the database with the new preference values.
This is a .net MVC ado based web app
Ques) How can I store these preference values into some list and later pass on/post to sql database.
view file code
<thead>
<tr >
<th>ID</th>
<th>Name</th>
<th>Active</th>
<th>Order By</th>
</tr>
</thead>
<tbody>
@if (ViewBag.data != null)
{
foreach (var item in ViewBag.data)
{
<tr>
<td>@item.AutoID</td>
<td>@item.Text<br </td>
<td >@item.Active</td>
<td>@item.OrderBy</td>
</tr>
}
}
</tbody>
<input name='OrderBy[]'>` / wrap the whole table in a<form>and submit the form. Some more info on posting array objects is here: haacked.com/archive/2008/10/23/model-binding-to-a-list.aspxOrderBycolumn.