I am creating a comparison table and want to be able to hide all of the rows in a datatable that have the same column 2 & and column 3 value. I have created a custom button that runs the below js:
action: function ( e, dt, node, config ) {
var rows = $("#compare").find("tbody tr"); //find all rows
rows.each(function() {
var thisRow = $(this),
value1 = thisRow.find("#1"),
value2 = thisRow.find("#2");
if(value1.text() == value2.text()){
thisRow.hide();
}
});
}
This does hide the rows on the current dataTable page that are duplicates, but still shows 10 results for that page even though all 10 are hidden. I read a few other questions, most of the answers recommended that a custom filter be applied to the rows due to serverside paging?
I would like the button to regenerate the table with only values where value1 !== value2, so if there are 25 results and 20 of them are duplicates, the table would be reloaded with showing results 1 to 5 of 5 entries.
datatable creation ->
success: function(data){
var Table = document.getElementById("compare");
Table.innerHTML = "";
$("#compare").append(data);
$("#compare").DataTable({
dom: 'Bfrtip',
buttons: [
{
text: 'My button',
action: function ( e, dt, node, config ) {
var rows = $("#compare").find("tbody tr"); //find all rows
rows.each(function() {
var thisRow = $(this),
value1 = thisRow.find("#1"),
value2 = thisRow.find("#2");
if(value1.text() == value2.text()){
$(this).hide();
}
});
//$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
// return table.row(dataIndex).nodes().to$().attr('excluded') != 'true'
//})
}
}
]
});
}