Skip to content

Instantly share code, notes, and snippets.

@mithun-daa
Created May 23, 2016 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mithun-daa/52026b744d6b0cb54b5ae08f07424150 to your computer and use it in GitHub Desktop.
Save mithun-daa/52026b744d6b0cb54b5ae08f07424150 to your computer and use it in GitHub Desktop.
onDrop(src: Todo, trg: Todo) {
this._moveRow(src.order, trg.order);
}
_moveRow(src, trg) {
src = parseInt(src);
trg = parseInt(trg);
// If the element was moved down
if (src > trg) {
for (let i = trg; i < src; i++) {
this.todos[i].order++;
}
} else { // if the element was moved up
for (let i = src + 1; i <= trg; i++) {
this.todos[i].order--;
}
}
this.todos[src].order = trg;
this.todos.sort((a, b) => a.order - b.order);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment