I want to remove duplicated rows in a html table, This is the code I have in js :
function removeDuplicateRows($table) {
var liText = '', liList = $('#adaccounts').find('td:first-child'), listForRemove = [];
$(liList).each(function () {
var text = $(this).text();
if (liText.indexOf('|' + text + '|') == -1)
liText += '|' + text + '|';
else
listForRemove.push($(this));
});
var all = '';
var idName = '';
$(listForRemove).each(function () {
var id = $(this).parents("tr").find('td').eq(0).text();
idName = id;
var names = $(this).parents("tr").find('td').eq(1).text();
var col = $('#adaccounts').find('tr').find('td').text();
if (col.includes(id)) {
all += ', ' + names;
}
$(this).parents("tr").remove();
});
idName = "#" + idName.trim();
$(idName).append(all);
}
removeDuplicateRows($('table'));
But if I add another row that is duplicated with another row that it wasnt duplicated before, all duplicates are added in the last duplicated row that it was found. How can I make it show duplicates in respective rows?
But when I add another tr in my table :
I get 
Aucun commentaire:
Enregistrer un commentaire