如何正确使用jquery datatable插件 [英] how to use jquery datatable plugin properly

查看:135
本文介绍了如何正确使用jquery datatable插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的示例代码,但是它不起作用.有人可以帮我如何使用这个jQuery数据表插件吗? 可以在sql结果字段表上使用此datatable插件吗?谢谢

Below is my example code, but it's not working. Can someone please help me on how to use this jquery datatable plugin? And can this datatable plugin used on sql result field table? Thanks

    <html>
    <head>
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"> 
    </head>

    <body>
       <table id="example"  style="border:1px solid black;">   
            <thead>


   <tr>
                <th>Column 1</th>         
                <th>Column 2</th>          
                <th>etc</th>       
            </tr>   
        </thead>

        <tbody> 
            <tr>       
                <td>Row 1 Data 1</td>
                <td>Row 1 Data 2</td>   
                <td>etc</td>   
            </tr>
            <tr>
                <td>Row 2 Data 1</td>
                <td>Row 2 Data 2</td> 
                <td>etc</td>  
           </tr>
            <tr>
                <td>Row 2 Data 1</td>
                <td>Row 2 Data 2</td> 
                <td>etc</td>  
           </tr>
       </tbody>
</table>
</body>

<script type="text/javascript">
    $(document).ready(function () {
        $('#example').dataTable();
    });
</script>

</html>

推荐答案

从文档中: https://datatables .net/manual/installation

要使DataTables能够增强HTML表,该表必须为 有效的,格式正确的HTML,带有标头(thead)和正文(tbody). 也可以使用可选的页脚(tfoot).

For DataTables to be able to enhance an HTML table, the table must be valid, well formatted HTML, with a header (thead) and a body (tbody). An optional footer (tfoot) can also be used.

尝试将thead添加到具有正确列数的表中.

Try adding a thead to your table with the correct number of columns.

它应该看起来像这样,但是需要有行和列,并且td充满了内容.

It should look like this, but with however rows and columns you need, and your td's filled with your content.

<table>
    <thead>
        <tr>
            <th></th>
            <th></th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </tbody>
<table>

这篇关于如何正确使用jquery datatable插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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