angularjs - How do I scroll an ngGrid to show the current selection? -


i'm setting selection of nggrid javascript, calling gridoptions.selectitem(). have multiselect set false, there ever 1 row selected. i'd nggrid automatically scroll show newly selected row, don't know how this: can help, please?

on related topic: can disable row selection mouse click? if so, how?

edited add

i'd disable keyboard navigation of selected row, if possible.

what worked:

aardvark71's answer worked. discovered nggrid defines property nggrid on gridoptions variable holds reference grid object itself. necessary functions exposed via properties of object:

$scope.gridoptions.selectitem(itemnumber, true); $scope.gridoptions.nggrid.$viewport.scrolltop(math.max(0, (itemnumber - 6))*$scope.gridoptions.nggrid.config.rowheight); 

my grid fixed @ 13 rows high, , logic attempts make selected row appear in middle of grid.

i'd still disable mouse & keyboard changes selection, if possible.

what worked:

this closer 'angular way' , achieves same end:

// $watch scrolls nggrid show newly-selected row close middle row possible $scope.$watch('gridoptions.nggrid.config.selecteditems', function (newvalue, oldvalue, scope) {             if (newvalue != oldvalue && newvalue.length > 0) {                 var rowindex = scope.gridoptions.nggrid.data.indexof(newvalue[0]);                 scope.gridoptions.nggrid.$viewport.scrolltop(math.max(0, (rowindex - 6))*scope.gridoptions.nggrid.config.rowheight);             }         }, true); 

although effect when row selected clicking on can bit disconcerting.

it sounds can make use of scrolltop method scrolling.

see http://github.com/angular-ui/ng-grid/issues/183 , following plunker @bryan-watts http://plnkr.co/edit/oyilx9?p=preview

an example how work follows:

function focusrow(rowtoselect) {   $scope.gridoptions.selectitem(rowtoselect, true);   var grid = $scope.gridoptions.nggrid;   grid.$viewport.scrolltop(grid.rowmap[rowtoselect] * grid.config.rowheight); } 


edit:

for second part of question "disabling mouse , keyboard events of selected rows" might best start new question. sounds want set enablerowselection dynamically false? no idea if that's possible.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -