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

Grouping on column + using scrollRowToTop or scrollRowToView #229

Open
larotech opened this issue Apr 5, 2018 · 1 comment
Open

Grouping on column + using scrollRowToTop or scrollRowToView #229

larotech opened this issue Apr 5, 2018 · 1 comment

Comments

@larotech
Copy link

larotech commented Apr 5, 2018

Hello,

When grouping is enabled for a column one cannot use scrollRowToTop or scrollRowToView simply with the row index as it is not accounting for the added height introduced by groups. For example, if I have a grid with row height set to 22 pixels and it has 1000 rows of data and in those rows there is 100 groups and I want to scroll to record 500, scrollRowToTop is doing 500 * 22px = height of div to scroll to.

Now since I have groups and lets say 50 groups come before record index 500 then it really should be (500 (record index) * 22px )+ (50 (number of groups before) * 22px) = actual height of div to scroll to.

Basically what i'm saying is it appears slidGrid does not support scrollRowToTop or scrollRowToView when using groups as the correct row never comes into view.

I've come up with this hack code to try to overcome this limitation but it only seems to work accurately if the grid is sorted in ascending order by the id field.

        var test = dataView.getItemByIdx(index);
        var groups = dataView.getGroups();

        var groupIdx = -1;
        for (var i = 0; i < groups.length; i++) {
            for (var r = 0; r < groups[i].rows.length; r++) {
                if (groups[i].rows[r].object_Id === test.object_Id) {
                    groupIdx = i;
                    break;
                }
            }
            if (groupIdx !== -1) {
                break;
            }
        }
        var newIndex = groupIdx !== -1 ? groupIdx + index : index;
        recordsGrid.scrollRowToTop(newIndex, false);
    };

I'm using the (2.3.16) build of SlickGrid

@6pac
Copy link
Owner

6pac commented Apr 22, 2018

Good catch. I don't have time to fix it properly, but this is the right approach - for row n, work out how many group total rows are between this row and the first row of the grid. We'd need to also allow the grid to call and external object to correct the row index, perhaps by passing the function to do the correction as a grid option?

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

2 participants