0

我想使用 KoGrid 显示“资产”列表,并在 Google 地图中显示相同的资产。当用户单击地图中的图钉时,列表中的相应资产应向下滚动以显示在顶部。奖励:如果它已经在视野中,请不要做任何事情。

我之前在不同的列表上做过这个,与排序和过滤的交互给我带来了一段时间的问题(我每次排序或过滤时都必须重新计算资产的索引)。

我可以用 koGrid 做到这一点吗?在切换到这个网格之前,我需要弄清楚这一点。任何示例或帮助表示赞赏。

4

1 回答 1

4

我认为您将需要获取对网格的引用并调用 grids$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
    }
}]
于 2013-05-05T04:36:34.630 回答