Hello,
UPDATED => new elements found for this bug, I have created a new post.
https://laracasts.com/discuss/channels/livewire/livewire-alpine-alpine-sort-plugin
I have this code.
<div
x-data="{
groups: $wire.entangle('groups').live,
activeGroup: $wire.entangle('activeGroup').live,
selectGroup(groupId) {
this.activeGroup = groupId;
},
sort: () => {
const ids = Array.from(document.querySelectorAll('[data-group_id]')).map(el => el.dataset.group_id);
axios.put('{{ route('tables.groups.sort', compact('table')) }}', { ids })
.then(response => {
console.log('Ordre mis à jour avec succès', response.data);
this.groups.sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id));
})
.catch(error => {
console.error('Erreur lors de la mise à jour :', error);
});
}
}"
>
<div class="flex gap-1" x-sort="sort">
<template x-for="group in groups" :key="'group-'+group.id">
<div
:class="{
'px-4 py-3 text-lg rounded-t-lg': true,
'bg-primary text-white': activeGroup === group.id,
'transition-all bg-white/30 backdrop-blur-xs cursor-pointer hover:bg-primary/30': activeGroup !== group.id,
}"
x-on:click="selectGroup(group.id)"
x-item
>
<template x-if="group.name">
<span x-text="group.name"></span>
</template>
<template x-else>
<span x-text="'Groupe '.group.order"></span>
</template>
</div>
</template>
@can ('create', [App\Models\Group::class, $table])
<x-ui.link href="{{ route('tables.groups.create', ['table' => $table]) }}">
<div
class="px-4 py-3 text-xl rounded-t-lg bg-white"
>
<span class="text-xl"><x-icons.create></x-icons.create></span>
</div>
</x-ui.link>
@endcan
</div>
@forelse ($groups as $groupIndex => $group)
@include('livewire.detail._table-group')
@empty
<div
:class="{
'flex-col gap-4 lg:gap-8 rounded-lg rounded-tl-none px-4 lg:px-8 py-4 lg:py-8 bg-white/30 backdrop-blur-xs': true,
}"
>
Aucun groupe n'a été créé pour ce tableau de calcul
</div>
@endforelse
</div>
I need to sort the groups.
The groups are ordered according to the order field stored in the table.
When I drag and drop to sort the tabs, I have a display bug : when I drag and drop several times, sometimes when I click on a tab, another tab disappears and I need to refresh the browser to get it back on the screen.
Something else (it's not a bug, but I don't see how to do that) : I can drag to the right the after the create link, but I'd like to stop the drag just before the create link.
Do you have any idea why some tab disappears ?
Do you have any idea how to prevent dragging too far to the right ?
Thanks for your help.
V