DataTables - 我不想在某些表上使用搜索/过滤器和长度选项

时间:2012-11-13 10:46:25

标签: jquery-datatables

如何在没有搜索过滤器和长度选择菜单的情况下初始化特定表格?

显然可以使用sDom选项完成,但文档非常糟糕,我无法完全理解我应该做什么。

http://datatables.net/usage/options#sDom

4 个答案:

答案 0 :(得分:88)

您可以在初始化数据表期间将此类属性设置为false:

"bFilter" : false,               
"bLengthChange": false

答案 1 :(得分:17)

由于 Datatables 1.10 ,您可以使用以下两个选项:

完整示例:

$('#example').dataTable( {
  "lengthChange": false,
  "searching": false
} );

答案 2 :(得分:5)

没有搜索过滤器和长度

var options = {"sDom": 'rtip'}
var myDataTable = $('#myDataTable')  
myDataTable.dataTable(options)

以下是官方文档中的示例:https://datatables.net/examples/basic_init/dom.html

答案 3 :(得分:3)

我同意sDom很棘手,我通过练习得到了它。运行下面的示例,看到“信息”将出现在顶部。用“sDom”替换sDom:'rtlp'并看到信息消失。现在使用“sDom”:'rtil'并看到信息返回到底部,但分页消失了。继续尝试,你会得到它。

<!DOCTYPE html>
<html>
 <head>
    <link href="demo_table.css" rel="stylesheet">
</head>
<body>
<table class="display dataTable" id="example">
    <thead>
        <tr role="row">
            <th>Rendering engine</th>
            <th>Browser</th>
            <th>Platform(s)</th>
            <th>Engine version</th>
            <th>CSS grade</th>
        </tr>
    </thead>
</table>
<script src="jquery.js"></script>
<script src="jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        $('#example').dataTable( {
            "aaData": [
                [ "Trident", "Internet Explorer 4.0", "Win 95+", 4, "X" ],
                [ "Gecko", "Firefox 3", "Win 2k+ / OSX.3+", 1.9, "A" ],
                [ "Webkit", "Safari 3.0", "OSX.4+", 522.1, "A" ]
            ],
            "sDom": '<"top"i>rtlp'
        } ); 
    } );
</script>       
</body>
</html>