Skip to content

x-sort handle breaks with x-for #4149

Answered by SimoTod
corsedag asked this question in 5. Bugs
Apr 15, 2024 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

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

<ul
    x-data="{ rows: ['fo…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@corsedag
Comment options

@docdunning
Comment options

Answer selected by corsedag
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants