我想使用KoGrid来显示“资产”列表,并在谷歌地图中显示相同的资产。当用户单击地图中的图钉时,列表中相应的资源应向下滚动以显示在顶部。奖励:如果它已经在视线中,就不要做任何事情。
我以前在不同的列表上这样做过,与排序和过滤的交互给我带来了一段时间的问题(每次排序或过滤时,我都必须重新计算资产的索引)。
我能用koGrid做到这一点吗?在切换到这个网格之前,我需要弄清楚这一点。任何例子或帮助都是非常感谢的。
发布于 2013-05-05 12:36:35
我认为您需要获取对网格的引用,并调用网格的$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
}
}]https://stackoverflow.com/questions/15226810
复制相似问题