jquery - Drag and Drop a collection is rails 4 app: How to get changes to persist? -
in rails app, have tasks has many sub_tasks. 1 tasks#show page have table lists sub_tasks related specific task.
<table> <tbody> <tr> <% @task.sub_tasks.each |sub_task| %> <td><%= sub_task.id %><td> <td><%= sub_task.name %><td> <td><%= sub_task.description %><td> </tr> </tbody> </table>
i've been able implement drag , drop on task database via http://benw.me/posts/sortable-bootstrap-tables/. however, question can drag , drop applied table of sub_tasks?
update: added following , got list sort. however, having trouble getting array placement persists.
<table> <tbody id="sortable"> <tr> <% @task.sub_tasks.each |sub_task| %> <td><%= sub_task.id %><td> <td><%= sub_task.name %><td> <td><%= sub_task.description %><td> </tr> </tbody> </table> <script> $(function (){ $("#drop").sortable(); }); </script>
i know have define sort method in tasks controller, guess question how pass position in @tasks.subtasks array params these changes persist?
if link, you've provided, there code, explains how asking
$('#sortable').sortable( axis: 'y' items: '.item' cursor: 'move' sort: (e, ui) -> ui.item.addclass('active-item-shadow') stop: (e, ui) -> ui.item.removeclass('active-item-shadow') # highlight row on drop indicate update ui.item.children('td').effect('highlight', {}, 1000) update: (e, ui) -> item_id = ui.item.data('item-id') console.log(item_id) position = ui.item.index() # not work paginated items, index 0 on every page $.ajax( type: 'post' url: '/things/update_row_order' datatype: 'json' data: { thing: {thing_id: item_id, row_order_position: position } } ) )
in update
function there code responsible updating position. have edit url request , add item-id
attribute table elements if didn't that. have take care update positions of other elements according changed(eg. moved first element bottom of table. of other elements position - 1)
Comments
Post a Comment