komarovalexander / ka-table

Lightweight MIT React Table component with Sorting, Filtering, Grouping, Virtualization, Editing and many more
http://ka-table.com
MIT License
769 stars 56 forks source link

Dynamically calculate page number of a row when grouping is implemented #416

Closed fshahmt closed 3 months ago

fshahmt commented 4 months ago

Hey again Alex, so I have an implementation where I calculate the index of the current item from the table.data key and then based on the index I change the page to that page and scroll that row into the view (ugly implementation bdw). I am facing an issue since I am using grouping.

If I use grouping and then have 20 items and set pagination to 5 per page then look for the 15th item which would be index 2 based on the table.data value but then since I am using grouping it adds another let's say 5 rows here and there and this even though I get 2 based on the calculations the item is actually on page 4 (index 3) since we have grouping working for us.

Since grouping is done on the fly when the table renders is there a way to get the updated data (with the group rows included)?

Not sure how to provide a demo but this is the best I could come up with - https://stackblitz.com/edit/table-paging-ts-8jsuqa?file=Demo.tsx.

Hope you already have this tackled and it was just me who couldn't find it.

komarovalexander commented 4 months ago

Hi @fshahmt to get all visible rows (including group rows) you can use getData https://stackblitz.com/edit/table-paging-ts-nivxzh?file=Demo.tsx

but table paging does not include groups in calculation, so if you enable grouping you will still have the same amount of data rows on the page

fshahmt commented 3 months ago

Thank you so much Alex, that was really helpful. Had to do some customisations but I got it working and it is beautiful now. Absolutely love how I can count on you to come to my rescue every time I get stuck trying to implement something new here. Will start writing blogs for some custom implementations and add them on stackblitz as well. Maybe add them to the demos (general) in case someone ever falls into the ditches I do.

Thank you again for always being so helpful along this 6+ months long journey I've had with Ka-table