How to count the number of combination of rows with a drop down list selection in datatables
I would like to count the number of rows in a table after making a selection in a drop down list (Name). but the only problem here is i would like to count number of rows basing on an other attribute in my table (position).
for example:
if i make a selection in the Name: Tiger Nixon
i would like to get
total rows: 3
Position 1 : 1 rows Position 2 : 1 rows Position 3 : 1 rows
Here the code I use to make a drop down list selection with attribute (Name) and it worked perfectly.
$(document).ready(function () {
$('#example').DataTable({
initComplete: function () {
this.api().columns(0).every(function () {
var column = this;
var select = $('<select class="Search"><option value=""></option></select>')
.appendTo($(column.header()))
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
}
});
$('.Search').change(function () {
if ($("#example > tbody > tr > td").length == 1) {
$('#Count').empty();
$('#Count').append('Count: 0' );;
} else {
$('#Count').empty();
$('#Count').append('Count: ' + $("#example > tbody > tr").length);
}
});
});
this pict for counting number of rows using just selection on Name
$('#table_id').DataTable().page.info().recordsDisplay
– colin0117
Jul 4 at 9:44
$('#table_id').DataTable().page.info().recordsDisplay
– Mohammed Ajeddig
Jul 4 at 10:48
– Mohammed Ajeddig
Jul 5 at 10:25
– colin0117
Jul 5 at 14:25
By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
– Peter B
Jul 3 at 9:50