Skip to content
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

vue-virtual-scroller isn't updating when the data changes #94

Closed
guanzo opened this issue Oct 13, 2018 · 6 comments
Closed

vue-virtual-scroller isn't updating when the data changes #94

guanzo opened this issue Oct 13, 2018 · 6 comments

Comments

@guanzo
Copy link

guanzo commented Oct 13, 2018

Demo: https://jsfiddle.net/9cp1qw8z/2/

vue-virtual-scroller isn't updating when my data changes. I know the data is reactive based on the demo.

@GreatAuk
Copy link

+1

@mgd216
Copy link

mgd216 commented Nov 26, 2018

I'm having the same problem, I have a list with RecycleScroller that when a user clicks an item in the list it opens a dialog to change the data. When the dialog closes the RecycleScroller does not update the current view until the user scrolls. To fix this I changed the following line:

src/components/RecycleScroller

360: } else {
361: view.nr.used = true
362: view.item = item //added this line
363: }

Now the view updates with the data changed by the user.

@mercs600
Copy link

mercs600 commented Dec 4, 2018

@guanzo @GreatAuk @mgd216 Guys, I thought I have the same issue, but I checked code and noticed that emitUpdate is props then I read documentation and saw:

emitUpdate (default: false): emit a 'update' event each time the virtual scroller content is updated (can impact performance).

So you have to just set the props on your recycle-scroller component

<DynamicScroller
    :emit-update="true">

@GreatAuk
Copy link

GreatAuk commented Dec 4, 2018

@guanzo @GreatAuk @mgd216 Guys, I thought I have the same issue, but I checked code and noticed that emitUpdate is props then I read documentation and saw:

emitUpdate (default: false): emit a 'update' event each time the virtual scroller content is updated (can impact performance).

So you have to just set the props on your recycle-scroller component

<DynamicScroller
    :emit-update="true">

I will try, thanks😁

@jrast
Copy link
Contributor

jrast commented Dec 19, 2018

I also encounter this problem, however, I'm not shure if its exactly the same. My example looks like this:

<template>
<v-app>
  <v-content>
    <v-container fluid>
      <recycle-scroller page-mode :items="citems" :item-height="48" content-tag="v-list" class="scroller">
        <v-list-tile slot-scope="{ item }" class="person-tile" tag="div">
          <v-list-tile-action>
            <text-icon colorize>{{ item.id }}</text-icon>
          </v-list-tile-action>

          <v-layout class="person-info" align-center>
            <v-flex xs12 sm8 md5 class="person-primary">
              {{ item.value }} - {{ item.test }}
            </v-flex>
          </v-layout>

          <v-btn icon @click.stop="increment(item.id)" href="#">
            <v-icon>edit</v-icon>
          </v-btn>
        </v-list-tile>


      </recycle-scroller>
    </v-container>
  </v-content>
</v-app>
</template>

<script>


export default {
  name: 'Demo',
  props: {},
  data() {
    return {
      items: [
        { id: 1, value: 0 },
        { id: 2, value: 0 },
        { id: 3, value: 0 },
      ],
    }
  },
  computed: {
    citems() {
      return this.items.map(e => ({ ...e, test: 1 }))
    },
  },
  methods: {
    increment(id) {
      const idx = this.items.findIndex(e => e.id === id)
      console.log(`Increment element ${idx}: ${this.items[idx].value} --> ${this.items[idx].value + 1}`)
      const elem = this.items[idx]
      elem.value++
      this.$set(this.items, idx, elem)
    },
  },
}
</script>

<style lang="stylus">

.scroller {
  height: 100%
}
</style>

Note that citems (the computed items) are used in the virtual scroller. If I change this line and use the items directly it seems to work!

@jrast
Copy link
Contributor

jrast commented Dec 19, 2018

I'm having the same problem, I have a list with RecycleScroller that when a user clicks an item in the list it opens a dialog to change the data. When the dialog closes the RecycleScroller does not update the current view until the user scrolls. To fix this I changed the following line:

src/components/RecycleScroller

360: } else {
361: view.nr.used = true
362: view.item = item //added this line
363: }

Now the view updates with the data changed by the user.

I can confirm that this solution works!

jrast added a commit to jrast/vue-virtual-scroller that referenced this issue Dec 19, 2018
@Akryum Akryum closed this as completed in 0635fa8 Dec 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants