2016-08-19 73 views
0
$(document).ready(function() { 


    $('#table_id').DataTable({ 
     initComplete: function() { 
     var select = $('<select><option value=""></option></select>'), 
      table = this; 
     select.on("change", function() { 
      table.api().column(0).search($(this).val()).draw(); 
     }); 
     $("#table_id").closest(".dataTables_wrapper").find(".dataTables_filter").append(select); 

     table.api().columns(0).data().eq(0).unique().sort().each(function(d, j) { 
      select.append('<option value="' + d + '">' + d + " - " + getClinicName(d) + '</option>'); 
     }); 
     } 
    }); 
    }); 

我有這個代碼,顯示一個下拉框顯示id(顯示爲d)和名稱。我也希望它顯示每行中的條目數量。下拉選擇行前顯示行數

例如:

如果第2行有5項,那麼我希望它顯示的ID名,5行狀id-name-#ofrows.

任何幫助嗎?

回答

-1

設置Count = 0並提高每一次打印出來..

$('#table_id').DataTable({ 
     initComplete: function() { 
      var select = $('<select><option value=""></option></select>'), 
       table = this; 
      select.on("change", function() { 
       table.api().column(0).search($(this).val()).draw(); 
      }); 
      $("#table_id").closest(".dataTables_wrapper").find(".dataTables_filter").append(select); 
      @int count = 1; 
      table.api().columns(0).data().eq(0).unique().sort().each(function(d, j) { 
       select.append('<option value="' + d + '">' + d + " - " + getClinicName(d) + " row no " + count + '</option>'); 
       count++; // increase count 
      }); 
     } 
    }); 
+0

沒有它沒有工作。 – jasmine825

+0

錯誤是什麼?在控制檯中查看是否有 –

+0

我看到沒有,只是我的整個下拉框消失了。 – jasmine825

0

我想你可以使用table.data().count()得到表的行數:

select.append('<option value="' + d + '">' + d + " - " + getClinicName(d) + " - " + table.data().count() + '</option>'); 
相關問題