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

Scroll to programatically selected item/row #571

Closed
ajantsch opened this issue Jul 17, 2013 · 2 comments
Closed

Scroll to programatically selected item/row #571

ajantsch opened this issue Jul 17, 2013 · 2 comments

Comments

@ajantsch
Copy link

Is there a possibility to scroll the grid to a programatically selected row that is out of the current grid viewport and actually not rendered because of the virtualization threshold?

@hamxiaoz
Copy link

I used a plugin, based on this idea: #183

Here is the relative code if you're interested (in coffee script):

plugin:

# plugin
class ScrollPlugin
  @grid = null

  # new child scope of the Grid scope for you to create watches or whatever you want.
  # gridInstance = instance of the grid object where the plugin is initialized.
  init: (childScope, gridInstance) ->
    @grid = gridInstance

  scrollTo: (entityIndex)->
    @grid.$viewport.scrollTop(@grid.rowMap[entityIndex] * @grid.config.rowHeight)

In grid controller:

$scope.scrollPlugin = new ScrollPlugin()
  $scope.gridOptions = { 
    plugins: [$scope.scrollPlugin]
    data: 'channels'
  }

$scope.findOnChannelName = ''

$scope.$watch 'findOnChannelName', (newValue, oldValue) ->
    return if (newValue == oldValue) || (newValue not in $scope.channelNames)

    # select the corresponding row
    angular.forEach $scope.channels, (data, index) ->
      if data.name == newValue
        $scope.gridOptions.selectItem(index, true)
        $scope.scrollPlugin.scrollTo(index)

@hamxiaoz
Copy link

hamxiaoz commented Sep 4, 2013

A plugin is not required, see this link for example.

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

3 participants