question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get the current visible group in a GroupedVirtuoso?

See original GitHub issue

Hey there, is there a way to efficiently get the current group in a GroupedVirtuoso? I currently do not see any Subscription for that.

I’ve tried to use rangeChanged but it seems it will misscount near the end of a list. See this example that is using the GroupedVirtuoso example in combination with rangeChanged.

Do I really have to add some kind of counting logic myself or did I miss something?

        rangeChanged={({startIndex}) => {
            let countLeft = startIndex;
            let group: string | undefined;
            for (let i = 0; i < groupSizes.length; i++){
                const groupSize = groupSizes[i] + 1/*groupHeader*/;
                if (countLeft - groupSize <= 0) {
                    group = groups[i];
                    break;
                }
                countLeft -= groupSize;
            }
            if (group) {
                console.log(group);
            }
        }}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
carstenpatzkecommented, Nov 10, 2020

It is literally like the the example that I’ve linked. But instead of Current visible range: I would like to see the current group. https://stackblitz.com/edit/react-xfltju?file=example.js

Technically there should be a list of all groups and I want to highlight the current group: https://virtuoso.dev/scroll-to-group/

0reactions
paulm17commented, Nov 16, 2021

So I finally got around thinking about this again and thanks to @carstenpatzke to providing the solution for me to work on.

useEffect(() => {
    const categoryRanges = {}
    categoryRanges[0] = { min: 0, max: 63 } // people
    categoryRanges[1] = { min: 64, max: 81 } // nature
    categoryRanges[2] = { min: 82, max: 98 } // food
    categoryRanges[3] = { min: 99, max: 109 } // activities
    categoryRanges[4] = { min: 110, max: 136 } // transport
    categoryRanges[5] = { min: 137, max: 168 } // objects
    categoryRanges[6] = { min: 169, max: 196 } // symbols
    categoryRanges[7] = { min: 197, max: 230 } // flags

    if (visibleRange[0]) {
      Object.keys(categoryRanges).forEach((_, index) => {
        const range = categoryRanges[index] as categoryRange
        const rangeMin = visibleRange[0] as number

        if (rangeMin >= range.min && rangeMin <= range.max) {
          snapshot.setCategoryId(index)
        }
      })
    }
  }, [visibleRange, snapshot])
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started with React Virtuoso | React Virtuoso
To start, install react-virtuoso in your React project. The package exports the Virtuoso , TableVirtuoso , GroupedVirtuoso , and VirtuosoGrid components.
Read more >
react-virtuoso - Bountysource
How to get the current visible group in a GroupedVirtuoso? $ 0 ... I'm currently using the VirtuosoGrid component to render a long...
Read more >
Virtuoso Visualization and Analysis XL User Guide
not make, and expressly disclaims, any representations or warranties as to ... Visible. Shows or hides the active graph. Split Current Strip.
Read more >
16.3.3.Business Intelligence Extensions for SPARQL
Virtuoso extends SPARQL with SQL like aggregate and "group by" ... Example for get counts and total prices of ordered items, grouped by...
Read more >
Issues · petyosi/react-virtuoso · GitHub
How to get the current visible group in a GroupedVirtuoso? #192 opened on Nov 9, 2020 by carstenpatzke.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found