简体   繁体   English

可滚动表,专注于行

[英]scrollable table, focus on row

jsfiddle code jsfiddle代码
I have a table with scrollable body. 我有一个带有可滚动机身的桌子。 Data is bound using knockout.js . 数据是使用knockout.js绑定的。 A single row from the body can be selected. 可以从主体中选择一行。
By default some row is selected. 默认情况下,选择某行。 But this row can be in the bottom of the body, in which case the user can't see it. 但是此行可以在主体的底部,在这种情况下,用户看不到它。 How can I make the selected row visible by default? 默认情况下,如何使所选行可见? I want to scroll the table to the selected row by default automatically when the page loads. 我想在页面加载时自动将表默认滚动到所选行。 The order of the data can't be changed. 数据的顺序无法更改。

Something like this: http://jsfiddle.net/aDahT/416/ 像这样的东西: http : //jsfiddle.net/aDahT/416/

var GetElementByClassName = function(matchClass){
  var elems = document.getElementsByTagName('*'), i;
    for (i in elems) {
        if((' ' + elems[i].className + ' ').indexOf(' ' + matchClass + ' ')
                > -1) {
            return elems[i];
        }
    }  
};

GetElementByClassName('selectedRow').scrollIntoView(true);

If you want a more comprehensive GetElementsByClass , you can check this out . 如果您想要更全面的GetElementsByClass ,可以进行检查 Newer browsers (see: not IE), have this baked in. 较新的浏览器(请参阅:不是IE)将其引入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM