2017-04-15 12 views
0

jquery datatableを使用してデータをテーブルに表示しました。すべて正常に動作します。私は問題があります。私のテーブルにはアクティブな&アクティブな顧客を示す列があります。私は以下のスクリプトを持っているアクティブな顧客&をアクティブにカウントしたい。これでは、各行にアクティブな値を持つ行を数えようとしていますが、行の総数を数えます。jqueryデータテーブルで特定の値を持つ行数をカウントする

<script type="text/javascript"> 
     $(document).ready(function() { 
      $('#example').dataTable({ 
       "bLengthChange": true, 
       "paging": true, 
       "sPaginationType": "full_numbers" ,     //For Different Paging Style 
       "scrollY": 400,          // For Scrolling 
       "jQueryUI": false,          //Enabling JQuery UI(User InterFace) 
       "lengthMenu": [[30, 50, 100, -1], [30, 25, 50, "All"]], 
       drawCallback: function (settings) { 
        var api = this.api(); 
        // get the number of rows, but remove the page:current if you want number of rows in entire dataset 
        var count = api.rows({ 
         api: $('#example tbody tr td[value="active"]') 
        }).data().length; 
        // this takes the count and appends it in a span tag to the dataTables pageinate div element 
        $('<span id="active_rows"></span>').html(count + ' rows').appendTo($('.dataTables_info')); 
       } 
      }); 
     }); 
    </script> 

答えて

0

カウントする行のフィルタリングに.filter()を使用できます。以下は、.filter()の使用例です。私はオプションの情報ページとほぼ同じ質問のフォーラムポストへのリンクも追加しました。

var count = api.rows 
      .column(0) 
      .data() 
      .filter(function (value, index) { 
        return value="active" ? true : false; 
      }).length; 
関連する問題