javascript - Save JQuery.Sortable results to SQL with ASP.NET MVC -



javascript - Save JQuery.Sortable results to SQL with ASP.NET MVC -

i've been looking @ number of threads this, i'm not getting it.

i have table pulls list sql. i'm using jquery.sortable sore rows on client side.

ideally, drag , sort rows in different orders , automatically save them in sql via controller using ajax.

here code:

<div class="container"> <table id="example" class="table table-responsive table-striped sorted_table"> <thead> <tr> <th>display order</th> <th>image/video</th> <th>title</th> <th>meta data</th> <th>action</th> </tr> </thead> <tbody> @foreach (var item in model) { order++; <tr id="@item.id"> <td>@order</td> <td><img src="~/images/home/@item.location" style="width: 100px;" /></td> <td>@item.title</td> <td>@item.meta</td> <td> <a href="@url.action("homebgdelete", "admin", new {id = item.id})">delete</a> </td> </tr> } </tbody> </table> <div class="col-sm-4">@html.actionlink("add another", "homebg", "admin")</div> <div><button id="submit-list" class="btn btn-default">save order</button></div> </div> <script> // sortable rows $('.sorted_table').sortable({ containerselector: 'table', itempath: '> tbody', itemselector: 'tr', placeholder: '<tr class="placeholder"/>', }); </script>

i've looked @ 1 method, iterates through dom , builds array of new order , passes array through ajax phone call controller process. i've tried of code no success.

any help great!

as rough thought (relating comments under questions), can iterate on table rows in update callback of sortable. there can access current element, ids, other attributes , indices, depending on need.

var ids = []; $('#example tbody').sortable({ update: function(event, ui) { $('#example tbody tr').each( function(index) { ids.push($(this).attr('id')); }); } });

javascript jquery asp.net ajax jquery-ui

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -