Skip to content

Instantly share code, notes, and snippets.

@MajesticPotatoe
Created December 10, 2018 18:47
Show Gist options
  • Save MajesticPotatoe/6d165b4c19f8d77710ec4a0df3334bbc to your computer and use it in GitHub Desktop.
Save MajesticPotatoe/6d165b4c19f8d77710ec4a0df3334bbc to your computer and use it in GitHub Desktop.
MoveableList
<template>
<v-flex>
<v-subheader>{{header}}</v-subheader>
<v-list class="cardContainer">
<v-list-tile
v-for="(item, i) in from"
:key="i"
@click="moveItem(to, from, item)"
>
<v-list-tile-title v-text="item[textKey]"></v-list-tile-title>
</v-list-tile>
</v-list>
</v-flex>
</template>
<script>
export default {
data: () => ({}),
props: ['to', 'from', 'textKey', 'idKey', 'header'],
methods: {
moveItem(to, from, item) {
const i = from.findIndex(m => m[this.idKey] === item[this.idKey]);
to.push(from[i]);
from.splice(i, 1);
this.sortArrays();
},
sortArrays() {
const sortFunc = (a, b) => {
if (a[this.textKey].toUpperCase() < b[this.textKey].toUpperCase()) {
return -1;
} if (a[this.textKey].toUpperCase() > b[this.textKey].toUpperCase()) {
return 1;
}
return 0;
};
this.to.sort((a, b) => (sortFunc(a, b)));
this.from.sort((a, b) => (sortFunc(a, b)));
},
},
};
</script>
<style>
.cardContainer{
height: 194px !important;
padding: 0px;
overflow-y: scroll !important;
border: 1px solid #818181;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment