Max*_*Max 10 angularjs ng-grid
我正在设置从JavaScript调用我的ngGrid的选择gridOptions.selectItem()
.我将multiSelect设置为false,因此只选择了一行.我希望ngGrid能够自动滚动显示新选择的行,但我不知道如何做到这一点:有人可以帮忙吗?
在相关主题:我可以通过鼠标单击禁用行选择吗?如果是这样,怎么样?
编辑添加
如果可能的话,我还想禁用所选行的键盘导航.
什么有效:
AardVark71的答案奏效了.我发现ngGrid ngGrid
在gridOptions
变量上定义了一个属性,它保存了对网格对象本身的引用.必需的函数通过此对象的属性公开:
$scope.gridOptions.selectItem(itemNumber, true);
$scope.gridOptions.ngGrid.$viewport.scrollTop(Math.max(0, (itemNumber - 6))*$scope.gridOptions.ngGrid.config.rowHeight);
Run Code Online (Sandbox Code Playgroud)
我的网格固定为13行高,我的逻辑尝试使所选行显示在网格的中间.
如果可能的话,我仍然希望禁用鼠标和键盘更改.
什么也有效:
这可能更接近'Angular Way'并达到同样的目的:
// This $watch scrolls the ngGrid to show a newly-selected row as close to the middle row as 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);
Run Code Online (Sandbox Code Playgroud)
虽然通过点击选择行的效果可能有点令人不安.
Aar*_*k71 14
听起来你可以使用scrollTop方法进行滚动.
另见http://github.com/angular-ui/ng-grid/issues/183以及来自@ bryan-watts的以下plunker http://plnkr.co/edit/oyIlX9?p=preview
这可行的一个例子如下:
function focusRow(rowToSelect) {
$scope.gridOptions.selectItem(rowToSelect, true);
var grid = $scope.gridOptions.ngGrid;
grid.$viewport.scrollTop(grid.rowMap[rowToSelect] * grid.config.rowHeight);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
对于问题的第二部分"禁用所选行的鼠标和键盘事件",最好开始一个新的问题.听起来你想将enableRowSelection动态设置为false?不知道是否可能.
归档时间: |
|
查看次数: |
11146 次 |
最近记录: |