SlickGrid
SlickGrid copied to clipboard
Grouping on column + using scrollRowToTop or scrollRowToView
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
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?