2

そのため、Datatablesプラグイン(http://datatables.net/)を使用してテーブル内のデータを並べ替えています。

私が保存したデータには、数値(22.34)、通貨($ 223,400)、およびフォーマットされた数値(233,623)が含まれます。プラグインを並べ替えるためのセクションがWebサイトにあります(http://datatables.net/plug-ins/sorting)。

私はこれを機能させるために過去2時間費やしましたが、何をしようとしてもエラーが発生し続けます。

これが私のコードです:

次のスクリプトが含まれています。

<script src="assets/js/dataTables.plugins.js"></script> 

これには次のものが含まれます。

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"formatted-num-pre": function ( a ) {
    a = (a==="-") ? 0 : a.replace( /[^\d\-\.]/g, "" );
    return parseFloat( a );
},

"formatted-num-asc": function ( a, b ) {
    return a - b;
},

"formatted-num-desc": function ( a, b ) {
    return b - a;
}
} );

次に、メインコード:

<script>   
    $(document).ready(function() {

     var oTable = $('#sample_1').dataTable( {
            "sDom": "<'row-fluid'<'span4'l><'span4 tbl_time_frame'><'span4'f>r>t<'row-fluid'<'span4'i><'span4'><'span4'p>>",
            "sPaginationType": "bootstrap",
            "aoColumns": [
               { "sType": "numeric"  },
               null,
               { "sType": "formatted-num"},
               { "sType": "numeric"},
               null,
               null,
               null,
               null,
               null
             ],
            "oLanguage": {
                "sLengthMenu": "_MENU_ records per page",
                "oPaginate": {
                    "sPrevious": "Prev",
                    "sNext": "Next"
                }
            },
            "fnInitComplete": jQuery('.tooltips').tooltip()
     });
});

ページの読み込み時に次のエラーが発生しました。

Uncaught TypeError: Cannot read property 'oSort' of undefined 

次に、3番目の行をクリックすると、次のエラーが交互に発生します。

Uncaught TypeError: Property 'formatted-num-asc' of object #<Object> is not a function jquery.dataTables.js:4038
Uncaught TypeError: Property 'formatted-num-desc' of object #<Object> is not a function 

誰か助けてもらえますか?

乾杯

4

2 に答える 2

1

The problem was to do with the order in which the files were included. I changed this and it solved the issue.

于 2013-02-15T09:02:34.363 に答える