我想你將需要得到一個參考網格,並調用網格$viewport.scrolltop
方法。注意:我沒有測試這個,我只是基於我做過的類似的東西寫的。
plugins: [{
onGridInit: function (g) {
// maybe add a method to your view model
viewModel.scrollTo = function (index, key) { // index of item in filter data, key is something i made up
if (index > g.filteredData().length - 8) { // 8 is the default excess_rows value in kogrid
g.$viewport.scrollTop(g.$viewport.scrollTop() + (g.config.rowHeight * index));
}
// if you want to select the row (set time out because ko grid dynamically creates the rows rendered in the grid)
setTimeout(function() {
var i = ko.utils.arrayFirst(g.renderedRows(), function (row) {
// some function that finds the entity
return row.entity.key === key;
});
if (i) {
g.selectionService.ChangeSelection(i) // this will select the row
}
}, 100);
}// assume self is your view model
}
}]