petyosi / react-virtuoso

The most powerful virtual list component for React
https://virtuoso.dev
MIT License
5.16k stars 299 forks source link

[BUG] GroupedVirtuoso and data prop don't work properly together, all of the data items don't get rendered #1030

Closed andleebsyed closed 7 months ago

andleebsyed commented 7 months ago

Hey there

Describe the bug In GroupedVirtuoso when data prop is passed, data items equal to the number of groups don't get rendered. For example if we have data array [1,2,3,4,5,6,7,8] and we are diving them into two groups. Internally number of elements to be shown get calculated from length of the data array (as per docs), which here is 8. In total 8 elements will get rendered. But as we have two groups , so we will have two groupHeadings which are Section one and Section two. So total number of elements which will be rendered will be 8 including the group headings. When ideally group heading should not interfere with the data array.

Reproduction Here ia a csb example for the same -> https://codesandbox.io/p/sandbox/sandpack-project-forked-qxsq2t?file=%2FApp.js%3A32%2C63

Expected behavior Data array with 8 elements, grouped in two sections of 4 items each, but as you can see in the example only 6 actual Items are getting rendered, with 2 group headings , total amounting to 8, when it should have been 10 elements in total, 8 data Items and two group headings.

andleebsyed commented 7 months ago

Hey @petyosi , thank you for your work. I can see that this is yet to be implemented. Actually i am having issues with implementing a chat system. My use case is inverse infinite scroll and new messages addition from UI. Going with the case where i am not passing the data prop, to render the item i am relying on the index which we get in itemContent callback, but that index depends on firstIndexItem passed initially. Suppose i passed 100 initially, now if i add a message from UI to the messages list, the index gets messed up. Maybe i don't know how to work with the api in this scenario as there isn't any example in docs which involves an input box wherein user can input a message. Is there an example somewhere or can you point me in the right direction how to handle an input box case in inverse infinite scroll.

petyosi commented 7 months ago

@andleebsyed I'm happy to assist you further and resolve your issues if your company sponsors the project.

andleebsyed commented 7 months ago

I am really sorry, but unfortunately that's not possible i suppose, as the main reason for creating an in-house chat is to reduce the cost, otherwise currently we are using one of the sdk for which we are paying. Again i am sorry for this, wish i could have helped here. If you can anyhow help, would really appreciate it.

andrconstruction commented 1 month ago

@andleebsyed faced with same problem, "groppedvirtuozo" not work correctly with an attribute "data", but work correctly with the "totalcount" instead. Replace data with totalcount and solve this problem