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

scrollTo() method #183

Closed
TomKaltz opened this issue Feb 23, 2013 · 14 comments
Closed

scrollTo() method #183

TomKaltz opened this issue Feb 23, 2013 · 14 comments
Assignees
Milestone

Comments

@TomKaltz
Copy link

Should be able to scroll to a certain row via an instance method. Also should be able to read the scrolling position somehow.

@orneryd
Copy link
Contributor

orneryd commented Feb 23, 2013

very easy with a plugin, get the grid instance and use

grid.$viewport.scrollTop(rowIndex * grid.config.rowHeight)

or for sorted data:
grid.$viewport.scrollTop(grid.rowMap[entityIndex] * grid.config.rowHeight) //entityIndex = the index of the data in your model.

@orneryd
Copy link
Contributor

orneryd commented Feb 23, 2013

we may end up just appending the grid instance to the options for easier access.

@ghost ghost assigned orneryd Feb 23, 2013
@TomKaltz
Copy link
Author

It works with virtual scrolling too?

On Sat, Feb 23, 2013 at 2:05 AM, Tim Sweet notifications@github.com wrote:

we may end up just appending the grid instance to the options for easier
access.


Reply to this email directly or view it on GitHubhttps://github.com//issues/183#issuecomment-13986360.

@orneryd
Copy link
Contributor

orneryd commented Feb 23, 2013

Yes

On Saturday, February 23, 2013, TomKaltz wrote:

It works with virtual scrolling too?

On Sat, Feb 23, 2013 at 2:05 AM, Tim Sweet <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>>
wrote:

we may end up just appending the grid instance to the options for easier
access.


Reply to this email directly or view it on GitHub<
https://github.com/angular-ui/ng-grid/issues/183#issuecomment-13986360>.


Reply to this email directly or view it on GitHubhttps://github.com//issues/183#issuecomment-13992217.

-Tim Sweet

@orneryd
Copy link
Contributor

orneryd commented Feb 23, 2013

added in 29b3bcb

@mikila85
Copy link

has the code been changed?
i cant find $scope.gridApi.grid.$viewport
there is no viewport in grid :(

@dprothero
Copy link

Agreed. @timothyswt There doesn't seem to be an obvious or documented way to scroll the grid from code anymore.

@dprothero
Copy link

My hack/workaround for now...

gridApi.grid.element[0].getElementsByClassName("ui-grid-viewport")[1].scrollTop = 0;

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 26, 2015

I think you're mixing 2.x and 3.0. The majority of this issue relates to 2.x I think, the last one from @dprothero looks like 3.0/ui-grid code.

For @dprothero, the cellNav feature provides the scrollTo functionality, and I believe that swalters is currently in the process of moving it into core.

@dereklin
Copy link

dereklin commented Apr 6, 2016

@dprothero Did you find a better solution? I am using a similar hack:

gridApi.grid.element[0].getElementsByClassName("ui-grid-viewport")[0].scrollTop = rowIndex * 25;

For me, I want to show the selected (at rowIndex) at the top of the grid view.

@dereklin
Copy link

dereklin commented Jun 6, 2016

@dprothero The hack doesn't work after the user sorts the table.
@PaulL1 gridApi.core.scrollTo works to some degree. It will select the row, but it won't try to make the selected row the first row in the viewport...

@dereklin
Copy link

dereklin commented Jun 7, 2016

My solution is to decorate uiGridDirective and then override the scrollTo and scrollToIfNecessary methods. The key is set up the scrollEvent.y according my business rule.

@dereklin
Copy link

dereklin commented Jun 7, 2016

I was not able to get the precise landing pixel. But I spotted the usage of

visibleRowCache.indexOf

So I went back with the hack. This time, I am using something like this to get the rowIndex:

                rowIndex = gridApi.grid.renderContainers.body.visibleRowCache.indexOf(gridApi.grid.rows[rowIndex]);
                gridApi.grid.element[0].getElementsByClassName("ui-grid-viewport")[0].scrollTop = rowIndex * gridApi.grid.options.rowHeight;

@Saransh27
Copy link

rowIndex = gridApi.grid.renderContainers.body.visibleRowCache.indexOf(gridApi.grid.rows[rowIndex]);
gridApi.grid.element[0].getElementsByClassName("ui-grid-viewport")[0].scrollTop = rowIndex * gridApi.grid.options.rowHeight;

Even above code is not working for me..did anyone solve it? In My case it works for 2-3 elements but after that it scrolls to end of the grid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants