sortablejs-vue3 icon indicating copy to clipboard operation
sortablejs-vue3 copied to clipboard

How to get the new list as an array?

Open idesignzone opened this issue 1 year ago • 1 comments

I have trouble getting the new array list. here is my code

<template>
  <div>
    <Sortable :list="elements" item-key="id" tag="div" :options="options" @change="DragableData($event)">
      <template #item="{ element, index }">
        <div :key="element.id">
          {{ index }} - {{ element.name }}
        </div>
      </template>
    </Sortable>
  </div>
</template>

<script setup>
const elements = [
  { id: "1", name: "one" },
  { id: "2", name: "two" },
  { id: "3", name: "three" },
  { id: "4", name: "four" },
];
const options = {sort: true};

function DragableData(data) {
  console.log(data)
}
</script>

data here does not have any array in it. is it possible to get new array?

idesignzone avatar Dec 04 '23 23:12 idesignzone

I did the following on the Sortable element I added: @end="(event) => onEnd(event)"

Then the onEnd function:

function onEnd(event) {
    array.splice(event.newIndex, 0, array.splice(event.oldIndex, 1)[0]);
}

eazyurk avatar Dec 11 '23 14:12 eazyurk