Created
May 23, 2016 01:30
-
-
Save mithun-daa/52026b744d6b0cb54b5ae08f07424150 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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