滚动到Datatable API中的特定行 [英] Scroll to specific row in Datatable API

查看:109
本文介绍了滚动到Datatable API中的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要像这样滚动到数据表中的特定行:

I need to scroll until specific row in my datatable like this:

https://datatables.net/extensions/scroller/examples/initialization/api_scrolling.html

这是我的代码:

        <script src="js/jquery-1.12.4.js"></script>
        <script src="js/jquery-3.1.1.min.js"></script>
        <script src="js/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="https://cdn.datatables.net/scroller/1.4.2/js/dataTables.scroller.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/form-builder.min.js"></script>
        <script src="js/jquery-ui.min.js"></script>
        ....
        <script>
            $(document).ready(function() {
                tableEntityList = $('#accentityListTable').DataTable({      
                    "ordering": false,  
                    "scrollY":"120px",
                    "scrollCollapse": true,
                    "paging":false, 
                    "dom":'<<"top"i>ft>',
                    "deferRender":true,
                    "scroller":true,    
                    "columnDefs": [
                        {"targets": [ 0 ],"visible": false}
                    ],
                    "createdRow": function( row, data, dataIndex ) {
                        if ( data[ 3 ] == "Inp" )
                            $(row).css('color', 'green')
                        else 
                            $(row).css('color', 'red')

                        if ( data[7] > 0 ) $(row).css('font-weight', 'bold')                        
                    },
                    "initComplete": function () {
                        alert("first");
                        this.api().row( 2 ).scrollTo();
                        alert("second");
                    }           

                });
    })
</script>

出现第一个警报:

alert("first");

但是第二个没有,

alert("second");

我做错了什么?

谢谢.

推荐答案

请替换为以下initComplete函数.会工作的.

Kindly replace with the below initComplete function. It will work.

"initComplete": function () {
    $('#example').DataTable().row(2).scrollTo();
}

注意:2代表n-1个目标行

Note: 2 represents n-1 targetted row

这篇关于滚动到Datatable API中的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆