vue-slicksort icon indicating copy to clipboard operation
vue-slicksort copied to clipboard

The list reverts back when sort is complete

Open rickmero opened this issue 5 years ago • 14 comments

When I drop my list item it reverts back. Is there anything I've forgot?

example

When I look at the list in my model/inspector everything looks correct. The actual model has been sorted, it is just a visual issue.

If I wrap the sortable list in a v-if and toggles the condition to force Vue to remove and add it back to the DOM the list renders correct.

rickmero avatar Jun 13 '19 13:06 rickmero

How do you insert keys? It should not be index of loop.

ghost avatar Jul 11 '19 05:07 ghost

@rickmero

  • are u binding key for the v-for? (do)
  • are you using an actual array? (use a proper array, not an object/map or similar)
  • are you using filter anywhere? (dont if the array consists of objects)

ghost avatar Aug 11 '19 13:08 ghost

Did you find a solution to this outside of an array? I am also getting the same issue as above, but my use case requires an object.

SlickSort issue

titusdecali avatar Oct 12 '19 11:10 titusdecali

YOu should generate static keys.

ghost avatar Oct 12 '19 18:10 ghost

YOu should generate static keys.

Can you give me a code example of how that might look? Thanks

titusdecali avatar Oct 13 '19 00:10 titusdecali

@synapse709 see my post above as the vue docs state, list items (v-for) always need to have a key bound for them to render properly

so essentially :key="record.key" where the key must be unique

ghost avatar Oct 13 '19 01:10 ghost

I've actually already tried that exactly, by adding a unique ID within each object and then setting :key="item.id", however this doesn't seem to change anything.

titusdecali avatar Oct 13 '19 01:10 titusdecali

are you handling the event properly? sorting doesnt mutate your array directly, the event returns a newly sorted array, which you then have to apply to your array

ghost avatar Oct 13 '19 02:10 ghost

Be sure the key doesn't update on sort. If you share code example i can edit on them.

ghost avatar Oct 13 '19 07:10 ghost

@synapse709 Close the issue if you solved. Or share your code.

ghost avatar Dec 09 '19 18:12 ghost

@synapse709 Close the issue if you solved. Or share your code. @rickmero opened this issue, not me.

titusdecali avatar Dec 10 '19 01:12 titusdecali

I have also this problem. Here is a reproductible: https://jsfiddle.net/x9fwdr8v/

@Jexordexan, the problem seems appears when the model refers to an array inside an object and when this array is dynamically added to the object.

Heziode avatar Oct 21 '20 19:10 Heziode

I had this same issue and it ended up being that my :key on my v-for loop was wrong (it was null/wrong property name)

ventralnet avatar Mar 19 '21 16:03 ventralnet

Seems, @Heziode is right.

My code:

<sortable-list
	axis="y"
	v-model:list="entity.channels"
	:use-drag-handle="true"
	v-show="hasChannels"
	@input="updateChannelsOrder"
>
	<EntityChannel
		v-for="(entityChannel, i) in entity.channels"
		:key="entityChannel.id"
		:index="i"
		:entity="entity"
		:entity-channel="entityChannel"
		@startLoading="loading=true"
		@stopLoading="loading=false"
		@updated="updated()"
	/>
</sortable-list>

After add or remote item to array entity.channels sorting is work internal (method updateChannelsOrder is run), but don't work visual (order of items reset to initial).

vjik avatar Jun 09 '22 10:06 vjik