2

I have a small application with tables like this:

<tr>
<td><img class='DeleteButton' alt=delete src='images/delete_icon.png'/></td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
<td>some Data</td>
<td class='toHide'>some Data</td>
<td>some Data</td>
<td>some Data</td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
</tr>

When I add new data in the table, I create a list with "suggestions" - data from the other data tables.

But if I have 3 tables(A,B,C), and some data(D) is in A and B, and when I want to add D to C, in the suggestion list there is D twice.

So how can I find duplicated rows in a table and how to do it the most efficient way?

(only the td-tags without class toHide matters)

So far I have used jQuery to get the suggestion list

 $("all the tables").not(myTable).each(function(){
       $(".suggestData table").append($(this).html());
 }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dirty-flow
  • 2,306
  • 11
  • 30
  • 49
  • 1
    I couldn't understand the question. – Ram Jun 14 '12 at 10:20
  • i get the data from different tables and add it to one table, and some of the td-s are dublicated, so i want to find and remove them – Dirty-flow Jun 14 '12 at 10:22
  • Not sure if that's how you formated the question, but your .suggestData table missing a ". – eric.itzhak Jun 14 '12 at 10:30
  • that was copy-paste-error in the question, i haven't copy the whole code,i fixed it. The append-function works, i just want to delete the dublicated rows – Dirty-flow Jun 14 '12 at 10:35
  • can you provide a [jsfiddle](http://www.jsfiddle.net)? – Ram Jun 14 '12 at 10:36
  • it would be difficult and i don't think it's necessary. I just have a table and i want to know if there are 2 rows, where the data in columns 5,7 and 8 are equal – Dirty-flow Jun 14 '12 at 10:48

1 Answers1

5

Read this post: This

Based on the post this is an example:

function removeD(w){
    var seen = {};
    if(w == 'val'){
        $('table tr td').each(function() {
            var txt = $(this).text();
            if (seen[txt])
                $(this).remove();
            else
                seen[txt] = true;
        });
    }else{
        $('table tr td').each(function() {
            var id = $(this).attr('id');
            if (seen[id])
                $(this).remove();
            else
                seen[id] = true;
        });
    }
}

$('#removeID').click(function(){
    removeD('id');
});



$('#removeVal').click(function(){
    removeD('val');
});

Fiddle

Community
  • 1
  • 1
Alex Ball
  • 4,404
  • 2
  • 17
  • 23
  • Thanks, thats what i wanted. I really have to search better the old questions. There is already answer to almost every question, but I don't find it – Dirty-flow Jun 14 '12 at 13:33