{"id":11673,"date":"2024-11-07T09:58:38","date_gmt":"2024-11-07T09:58:38","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=11673"},"modified":"2024-11-07T09:58:38","modified_gmt":"2024-11-07T09:58:38","slug":"automatically-update-order-field-with-vuedraggable","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/vue\/automatically-update-order-field-with-vuedraggable","title":{"rendered":"How to Automatically Update &#8220;order&#8221; Field of an Item Using VueDraggable?"},"content":{"rendered":"<h2>Steps<\/h2>\n<p>Add the end event handler to the draggable component. This event is fired after the drag-and-drop action is completed.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n&lt;draggable v-model=\"items\" @end=\"onEnd\"&gt; &lt;div v-for=\"item in items\" :key=\"item.order\"&gt; {{ item.name }} &lt;\/div&gt; &lt;\/draggable&gt;\r\n<\/pre>\n<p>Update the order of the items within the event handler.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\nonEnd(event) { \r\n this.items.forEach((item, index) => { item.order = index; }); \r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Steps Add the end event handler to the draggable component. This event is fired after the drag-and-drop action is completed. &lt;draggable v-model=&#8221;items&#8221; @end=&#8221;onEnd&#8221;&gt; &lt;div v-for=&#8221;item in items&#8221; :key=&#8221;item.order&#8221;&gt; {{ item.name }} &lt;\/div&gt; &lt;\/draggable&gt; Update the order of the items within the event handler. onEnd(event) { this.items.forEach((item, index) => { item.order = index; }); }<\/p>\n","protected":false},"author":1,"featured_media":11674,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-11673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vue"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/11673"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=11673"}],"version-history":[{"count":1,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/11673\/revisions"}],"predecessor-version":[{"id":11675,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/11673\/revisions\/11675"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/11674"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=11673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=11673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=11673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}