包括JSON到datatables插件

时间:2013-04-26 15:29:47

标签: json datatables jquery-datatables

我想将我的JSON列表包含在datatables插件表中,我有代码,但有些东西不起作用; /也许你会帮忙:]我有代码显示theader并构建一个表 - 它工作正常,但是当我将脚本包含在代码中时出现问题; / datables 1.9.4版本

代码:

  <html>
<head>
<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/media/images/favicon.ico" />

        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
        <style type="text/css" title="currentStyle">

            @import "css/table.css";
        </style>
        <script type="text/javascript" language="javascript" src="js/jquery.js"></script>
        <script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
        <script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>
        <script type="text/javascript" charset="utf-8">
            jQuery.fn.dataTableExt.oSort['numeric-comma-asc']  = function(a,b) {
                var x = (a == "-") ? 0 : a.replace( /,/, "." );
                var y = (b == "-") ? 0 : b.replace( /,/, "." );
                x = parseFloat( x );
                y = parseFloat( y );
                return ((x < y) ? -1 : ((x > y) ?  1 : 0));
            };

            jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) {
                var x = (a == "-") ? 0 : a.replace( /,/, "." );
                var y = (b == "-") ? 0 : b.replace( /,/, "." );
                x = parseFloat( x );
                y = parseFloat( y );
                return ((x < y) ?  1 : ((x > y) ? -1 : 0));
            };

            $(document).ready(function() {
                $('#example').dataTable( {
                    "aoColumns": [
                        null,
                        null,
                        null,
                        { "sType": "numeric-comma" },
                        null
                    ]
                } );
            } );
        </script>













        <script>

    $(document).ready(function() {

    //code here
    var jsondata=$.parseJSON('{"response":[["name0","id0","amt0"],["name1","id1","amt1"]]}');

    $.each(jsondata.response, function(i, d) {
        var row='<tr>';
        $.each(d, function(j, e) {
             row+='<td>'+e+'</td>';
        });
        row+='</tr>';
        $('#example').append(row);
    });

});
        </script>
</head>


<body id="dt_example">


<div id="container">



            <div id="demo">


<table  cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr><th>header1</th><th>header2</th><th>header3</th></tr>
    </thead>

</table>
</div>




            </div>

</body>
</html>

0 个答案:

没有答案