Dropdown to display amount of rows before selecting

Dropdown to display amount of rows before selecting

jasmine825jasmine825 Posts: 5Questions: 5Answers: 0

I have a code

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

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

I have this code and I want to add the number of entries next to each selection. For example, if id one returns 5 rows then I want my dropdown to show

one-name-5 rows

Answers

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    Sounds like you need to "bin" the data - i.e. count how many of each occurrence there is. My alphabet search plug-in does that if you have to take a look at one possible way to implement such a feature.

    Allan

This discussion has been closed.