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

Manually trigger infinite #82

Open
timoteiNicsoft opened this issue Apr 3, 2024 · 6 comments
Open

Manually trigger infinite #82

timoteiNicsoft opened this issue Apr 3, 2024 · 6 comments

Comments

@timoteiNicsoft
Copy link

timoteiNicsoft commented Apr 3, 2024

I'm working in Vue 3, and I'm trying to manually trigger the infinite scroll because on small screens, the loader is larger than the screen, so the infinite scroll doesn't render only when scrolling down to the bottom of the page.

I've tried this:

<InfiniteLoading :identifier="infiniteId" @infinite="infiniteProceduresHandler" :firstload="false" ref="infiniteLoadingRef">
     <template #complete><span></span></template>
     <template #spinner><span></span></template>
</InfiniteLoading>

<script setup lang="ts">

onMounted(async () => {
         await nextTick(() => {
             infiniteLoadingRef.value?.$emit('infinite', infiniteLoadingRef.value.stateChanger);
         });
});
</script>

the problem is that in the infiniteProceduresHandler function it does not recognize $state.

@timoteiNicsoft timoteiNicsoft changed the title Trigger infinite manually Manually trigger infinite Apr 3, 2024
@timoteiNicsoft
Copy link
Author

Hi,

I tried using infiniteLoadingRef.value.$emit('infinite') but I still get the same error. It shows that it doesn’t recognize $state.

@jTiKey
Copy link

jTiKey commented Jun 7, 2024

@timoteiNicsoft hey, I deleted my answer because it wasn't working correctly.
You can save the state from the initial load function but then it will stop working once you do that if you use the complete command, then it won't load anymore.

@timoteiNicsoft
Copy link
Author

But I don’t have the initial state because, on small screens, the loader template is larger than the page, and I need to trigger it manually; otherwise, the loader stays on the entire page.

It used to work before, but now, with the Vue 3 version, it no longer works.

@jTiKey
Copy link

jTiKey commented Jun 7, 2024

vuetify has an infinite scroller that has a manual mode, you could try that one.

@GMolini
Copy link

GMolini commented Sep 19, 2024

I honestly cant understand why there is a prop for firsload=false but then we cant trigger manually the first load. Just In case its helpful for anyone, my problem was that the data being presented to the loader was really being fetched in a store in another part of the application. But I wanted only to show the first n elements and then load them on the screen using the infinite loader.

The problem was that, on page reload, the component mounted before the data had been fetched, so it would display no results. My 'hack' was to make a function to wait for data to be there

    const waitForDataArray = () => {
      return new Promise((resolve) => {

        if (data_array.value.length > 0) {
          resolve();
        }
        const unwatch = watch(data_array, (newVal) => {
          if (newVal.length > 0) {
            unwatch(); // Stop watching once the condition is met
            resolve();
          }
        });
      });
    };

Then in the async load function you can just use await waitForDataArray. If you are navigating through the app and data is already in the array, it will automatically continue and resolve the promise. If not, it will wait until it has been fetched

@hardik-baraiya-123456
Copy link

hardik-baraiya-123456 commented Oct 9, 2024

templet

<InfiniteLoading @infinite="load" :identifier="infiniteId">
<template #complete>


    // script
    
    const infiniteId = ref(+new Date()); // It will generate a random value based on current time
    
    // show apply filter
  const applyFilter = () =>{
      page.value = 1;
      list_data.value = [];
      infiniteId.value += 1;
  }

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

4 participants