首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >KoGrid -自动滚动到选定对象

KoGrid -自动滚动到选定对象
EN

Stack Overflow用户
提问于 2013-03-05 22:50:35
回答 1查看 1.1K关注 0票数 0

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

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

我能用koGrid做到这一点吗?在切换到这个网格之前,我需要弄清楚这一点。任何例子或帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2013-05-05 12:36:35

我认为您需要获取对网格的引用,并调用网格的$viewport.scrolltop方法。注意:我没有测试这个,我只是基于我做过的类似的事情来写的。

代码语言:javascript
复制
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
    }
}]
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15226810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档