-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sortable shows new added item not at the end but in between #6
Comments
Thank you for the detailed PR! I'll take a closer look at it this weekend and hopefully get a fix put in. |
I created two better examples. Resort the item array manually in
|
I modified the code example by adding keys to Svelte each blocks as described keyed-each-blocks |
Hey, not sure if you're still having issues with this. Sorry. I just looped over your first example and it was fixed by doing. I think the main issue with Svelte is them not having the unique key indexes like you mentioned. <script>
import { SortableList } from '@jhubbardsf/svelte-sortablejs';
let data = [{id: 0, val: 'Item 1'}, {id: 1, val: 'Item 2'}, {id: 2, val: 'Item 3'}];
// let sortableListData = [...data];
$: {
console.log(`data: ${data}`);
}
const addItem = () => {
const item = `Item ${data.length + 1}`;
data = [...data, {id: data.length, val: item}];
// sortableListData = [...data];
};
const move = (arr, from, to) => {
const input = [...arr];
let numberOfDeletedElm = 1;
const elm = input.splice(from, numberOfDeletedElm)[0];
numberOfDeletedElm = 0;
input.splice(to, numberOfDeletedElm, elm);
data = [...input];
};
const handleEnd = (evt) => {
move(data, evt.oldIndex, evt.newIndex);
// data = [...data];
};
</script>
<svelte:head>
<title>Home</title>
<meta name="description" content="Svelte demo app" />
</svelte:head>
<section>
<h1>Sortable Test</h1>
<div class="margin-auto ">
<button class="button" on:click={addItem}>Add</button>
<SortableList class="list-group col" animation={150} ghostClass="bg-info" onEnd={handleEnd}>
{#each data as item (item.id)}
<div class="list-group-item">
{item.val}
</div>
{/each}
</SortableList>
</div>
</section>
<style>
.margin-auto {
margin: auto;
}
.list-group.col {
background-color: blue;
color: white;
}
.list-group-item {
background-color: gray;
color: white;
margin: 20px 0;
padding: 8px 8px;
}
.button {
padding: 8px;
background-color: green;
color: white;
}
</style> |
Thank you very much for the great work and Svelte implementation.
Issue
Resorting by drag and drop does not work correct after an additional item is added.
The item the user drops at position A, sortable puts it to position A-1.
Situation
Goal
The goal ist to save the sorted data (not html) to database. Therefor a array of data is used.
Steps to Reproduce
Thank you in advanced for your response.
The text was updated successfully, but these errors were encountered: