How do i get rows count match dropdown value?

How do i get rows count match dropdown value?

muakomuako Posts: 9Questions: 1Answers: 0
edited September 2021 in Free community support

Original option: Apple Should be Apple - 3

<select class="dropdown_class">              
  <option>Apple - 3</option>
  <option>Banana - 1</option>
 <select>  

<table id="table_id" class="display">
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Apple</td>
            <td>Mango</td>
        </tr>
        <tr>
            <td>Apple</td>
            <td>Apple 2</td>
        </tr>
         <tr>
            <td>Apple</td>
            <td>Mango</td>
        </tr>
        <tr>
            <td>Banana</td>
            <td>Orange</td>
        </tr>
    </tbody>
</table>
$('#example').DataTable( {               
                var column = this;              
                   $('.dropdown_class') .on( 'change', function () {
                        var val = $.fn.dataTable.util.escapeRegex(
                            $(this).val()
                        );
                        column.search( val ? '^'+val+'$' : '', true, false ).draw();
                    } );
            } );     
    } );

I have to ready above example and the dropdown filtering working as well but i cant understand how is append to option for the rows count match dropdown value.

Replies

  • kthorngrenkthorngren Posts: 20,273Questions: 26Answers: 4,765

    Take a look at this example. Its using this code to build the select lists:

                    column.data().unique().sort().each( function ( d, j ) {
                        select.append( '<option value="'+d+'">'+d+'</option>' )
                    } );
    

    You can change the loop to build the lists the way you want. Try removing the .unique() so all of the column data is looped through. In the loop you can keep track of the number of times each value occurs and add to the select list when the value changes.

    Kevin

  • muakomuako Posts: 9Questions: 1Answers: 0

    Any example?

Sign In or Register to comment.