Replies: 4 comments 5 replies
-
@daybrush Is there a way to use IG with Relay cursors? |
Beta Was this translation helpful? Give feedback.
-
Can I understand that groupKey cannot be set because there is no page number? If so, there seem to be two ways.
|
Beta Was this translation helpful? Give feedback.
-
Yes. Because react child key is used, both string and number are allowed as long as it is unique. |
Beta Was this translation helpful? Give feedback.
-
@daybrush - I'm passing my array of
Svelte fileHere's <script lang="ts">
import { GetObservations } from '$lib/generated';
import { onMount } from 'svelte';
let filter;
$: observations = GetObservations({ variables: filter });
import Item from '$lib/components/observation/Item.svelte';
import { MasonryInfiniteGrid } from '@egjs/svelte-infinitegrid';
import { tick } from 'svelte';
$: pageInfo = $observations.data?.observations?.pageInfo;
let items = [];
$: newItems = $observations.data?.observations?.edges;
let ig;
onMount(() => {
console.log(ig.getItems());
});
function handleNext() {
if (pageInfo) {
$observations.query.fetchMore({
variables: {
filter: filter,
after: pageInfo.endCursor
}
});
}
}
</script>
{#if $observations.loading}
Loading...
{:else if $observations.error}
{$observations.error}
{:else if $observations.data}
{(items=newItems)}
<MasonryInfiniteGrid
class="grid ig"
useLoading={true}
gap={5}
{items}
on:requestAppend={({ detail: e }) => {
e.wait();
handleNext();
e.ready();
if (newItems.length && pageInfo.hasPreviousPage) {
items = [...items, ...newItems];
}
}}
let:visibleItems
>
{@debug items} <!-- array has items -->
{@debug visibleItems} <!-- empty array -->
{#each visibleItems as edge (edge.key) //should this be edge.cursor?}
<Item {edge} />
{/each}
</MasonryInfiniteGrid>
{/if}
<style>
:global(.ig) {
height: 600px;
}
</style> Am I passing react child key ( items (from dev tools)Here is an example
The visibleItems (from dev tools)Even with
|
Beta Was this translation helpful? Give feedback.
-
Hi - thank you for all of this work.
In my project, i am querying the items from a GraphQL server, and the server returns the results using "Relay-style" cursor-based pagination. The cursor is a long unique string, not a number. There are no "page numbers" in this style of pagination, it just refers to the keys for
startCursor
andendCursor
of each next group of items returned (each page, in other words).Reading through the IG API it seems the items are indexed by a numerical
key
, and number offsetgroupKey
. I'm wondering if IG can work with cursor-based pagination.Or maybe,
onRequestAppend
i can handle my query separately using my own fetch function, and just append the new items to IG. Do i need to add a numericalitemBy
andgroupBy
when i append items?... or, how should i handle it if my cursors are not numerical?Sorry, i'm just getting my head around how IG works. Please let me know if I'm missing something :)
Beta Was this translation helpful? Give feedback.
All reactions