我從JavaScript設置我的ngGrid的選擇,呼叫gridOptions.selectItem()
。我將multiSelect設置爲false,因此只有一行被選中。我想ngGrid自動滾動顯示新選擇的行,但我不知道該怎麼做:任何人都可以幫忙嗎?如何滾動ngGrid以顯示當前選擇?
關於相關主題:可以通過鼠標單擊禁用行選擇嗎?如果是這樣,怎麼樣?
編輯補充
我也想停用選定行的鍵盤導航,如果可能的話。
什麼工作:
AardVark71的答覆工作。我發現ngGrid在gridOptions
變量上定義了一個屬性ngGrid
,該變量持有對網格對象本身的引用。必要的功能都通過該對象的屬性暴露:
$scope.gridOptions.selectItem(itemNumber, true);
$scope.gridOptions.ngGrid.$viewport.scrollTop(Math.max(0, (itemNumber - 6))*$scope.gridOptions.ngGrid.config.rowHeight);
我的網格被固定在13行高,和我的邏輯試圖使所選擇的行出現在網格的中間。
我還想禁用鼠標&鍵盤如果可能,請更改選擇。
什麼還曾:
這可能是更接近「角之路」,達到同樣的目的:
// 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);
雖然效果一行時,通過點擊它選擇能有點令人不安。
你可以顯示你到目前爲止得到的代碼嗎?這聽起來像你可以使用scrollTop方法。另請參閱https://github.com/angular-ui/ng-grid/issues/183以及以下來自@ bryan-watt的運動員http://run.plnkr.co/plunks/oyIlX9/ – AardVark71
好的,我已經得到了它的工作,感謝這個提示!有一個未記錄的'ngGrid'屬性被添加到'gridOptions'屬性中,該屬性持有對實際網格本身的引用。這個函數調用來滾動視口然後是'$ scope.gridOptions.ngGrid。$ viewport.scrollTop(rowNumber * $ scope.gridOptions.ngGrid.config.rowHeight)'AardVark71 - 請將這個更新爲答案&我會信任你: 非常感謝! – Max
很高興爲你效勞,我將其解釋爲答案 – AardVark71