Integrating SortableJS in Phoenix LiveView for Drag-and-Drop Lists

224
clicks
Integrating SortableJS in Phoenix LiveView for Drag-and-Drop Lists
Berenice Medel's post discusses how to enhance Phoenix LiveView applications with the capability for users to drag and drop list items using SortableJS, a JavaScript library. The article begins with setting up a `ListComponent` with Phoenix 1.7's function components and continues by guiding the reader through the tasks of adding SortableJS to the project, configuring it, and implementing the JavaScript hook required for frontend behavior. Medel then shows how to improve the visual feedback during the drag-and-drop operations using Tailwind CSS classes and details how to handle events sent from the client to the server. The application is also extended to allow items to be dragged across multiple lists by sharing a group identifier. Lastly, the post points out that while the drag-and-drop function works, persistence of changes and list element management can be further improved by utilizing LiveView features.

© HashMerge 2024