-
Very excited about the new The example provided in the documentation works great, only the hyphen is draggable: <ul x-sort>
<li>
<span x-sort:handle> - </span>foo
</li>
<li>
<span x-sort:handle> - </span>bar
</li>
<li>
<span x-sort:handle> - </span>baz
</li>
</ul> However, when using <ul
x-data="{ rows: ['foo', 'bar', 'baz'] }"
x-sort
>
<template x-for="row in rows">
<li>
<span x-sort:handle> - </span><span x-text="row"></span>
</li>
</template>
</ul> Perhaps there's a workaround by adding some custom config but I have not explored this yet. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I don't think x-for and z-sort are fully compatible yet (There are odd behaviours when adding a new element to the list since the order in x-for doesn't stay in sync with x-sort). Re the handle, it won't work because the plugin looks for a child element with the As a workaround for now, you can add UPDATE:
|
Beta Was this translation helpful? Give feedback.
-
See my solution here: #4157 (comment) |
Beta Was this translation helpful? Give feedback.
I don't think x-for and z-sort are fully compatible yet (There are odd behaviours when adding a new element to the list since the order in x-for doesn't stay in sync with x-sort).
Re the handle, it won't work because the plugin looks for a child element with the
x-sort:handle
attribute (https://github.com/alpinejs/alpine/blob/main/packages/sort/src/index.js#L23C46-L23C63) but when the plugin runs, the x-for item haven't been generated (querySelector doesn't drill inside the template) so it just initialise the plugin with the normal behaviour.As a workaround for now, you can add
x-sort:handle
to the template tag.UPDATE:
You can also manually force it by doing