How do i get rows count match dropdown value?
How do i get rows count match dropdown value?
muako
Posts: 9Questions: 1Answers: 0
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
Take a look at this example. Its using this code to build the select lists:
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
Any example?