-1

I have table in html.... I need to: if i have two or more almost identical rows (first check with uppercase and without spaces and other symbold... just numbers and letters), i must delete all, and keep one, but only such, where i have some value in td... Take look at example:

Bosch | 1234s | details
BOSCH | 1234S | 
ATE | 1215 | details

i must keep only such table:

Bosch | 1234s | details
ATE | 1215 | details

Just if there are same (with uppercase and without spaces and other symbold... just numbers and letters) then delete all same rows, and keep such, where in third row i have details...

I'm not good in javascript.... Please help me (just do not minus, or close)... I googled some sortings... But how to delete almost duplicates didn't know....

also now i have tablesorter:

$(document).ready(function() { 
        $(".sortable") 
        .tablesorter({sortList: [[4,0]], widgets: ['zebra']});
    }); 
S M
  • 8,155
  • 3
  • 35
  • 36
brabertaser19
  • 5,678
  • 16
  • 78
  • 184

1 Answers1

0

Starting for this answer and using your table.

<table cellpadding="0" cellspasing="0" class="sortable zebra tablesorter tablesorter-default" id="articles-table">
              <thead>
                <tr class="tablesorter-headerRow">
                  <th data-column="0" class="tablesorter-header"><div class="tablesorter-header-inner">Производитель<i class="tablesorter-icon"></i></div></th>
                  <th data-column="1" class="tablesorter-header"><div class="tablesorter-header-inner">Артикул<i class="tablesorter-icon"></i></div></th>
                  <th data-column="2" class="tablesorter-header"><div class="tablesorter-header-inner">Описание<i class="tablesorter-icon"></i></div></th>
                  <th data-column="3" class="tablesorter-header"><div class="tablesorter-header-inner"><i class="tablesorter-icon"></i></div></th>
                  <th class="prcol  tablesorter-header tablesorter-headerSortDown" data-column="4"><div class="tablesorter-header-inner">Цена<i class="tablesorter-icon"></i></div></th>
                  <th data-column="5" class="tablesorter-header"><div class="tablesorter-header-inner">Наличие<i class="tablesorter-icon"></i></div></th>
                  <th data-column="6" class="tablesorter-header"><div class="tablesorter-header-inner">Сроки поставки<i class="tablesorter-icon"></i></div></th>
                  <th data-column="7" class="tablesorter-header"><div class="tablesorter-header-inner"><i class="tablesorter-icon"></i></div></th>
                </tr>
              </thead>
              <tbody class="analogs_art">


             <tr class="zebra-stripe zebra-grey zebra2 even">
                  <td>
                    <h5>
                      Knecht
                    </h5>
                  </td>
                  <td>
                    <h4>
                      OC90
                    </h4>
                  </td>
                  <td style="max-width: 300px;">
                    (07786171)Фильтр масл OPEL
                    (07786171)Фильтр масл OPEL
                  </td>
                  <td>
                  </td>
                  <td>
                    6124
                  </td>
                  <td>
                    20
                  </td>
                  <td>
                    0-1
                  </td>
                  <td id="to_cart_and_qnt_td">


                      <form accept-charset="UTF-8" action="/line_items" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="0jlRLSkDKi6eM5SSL+3uRB0w2G141KUcJKuy4Bg2YNo="/></div>
                          <input id="ART" name="ART" type="hidden" value="y1M1ZtdXgnMe6pOjjuXWPqhYR41SmQRKzlDOQ1uPwuru+AamPGpcOwOFFylbRDu5M1XUawCnukqNDQCuIr0JPA==--vNGx6/lYKRrpD5NGTJALcQ=="/>

                          <input id="price" name="price" type="hidden" value="TodzvfOZCbK5T9+RLE1IQg==--qq8o30c5rTX91F8W42wdsQ=="/>
                          <input id="distributor_id" name="distributor_id" type="hidden" value="6"/>
                          <input id="waittime" name="waittime" type="hidden" value="1"/>
                          <input class="qnt_to_cart2" id="OC90" name="cart_quantity" pattern="0|[1-9]\d{0,2}" required="required" type="text" value="1"/>
                          <input class="orange-button to-cart_no" id="OC90" name="commit" type="submit" value="В корзину"/>
                    </form>
                  </td>
                </tr><tr class="zebra-stripe zebra-grey zebra2 odd">
                  <td>
                    <h5>
                      KNECHT

                    </h5>
                  </td>
                  <td>
                    <h4>
                      OC 90
                    </h4>
                  </td>
                  <td style="max-width: 300px;">
                    Масляный фильтр
                  </td>
                  <td>
                    <a href="/articles/1248525/details" class="details-link">подробнее</a>
                    <a href="/articles/1248525" class="analogs-link">аналоги</a>
                  </td>
                  <td>
                    6124
                  </td>
                  <td>
                    20
                  </td>
                  <td>
                    0-1
                  </td>
                  <td id="to_cart_and_qnt_td">
                    <form accept-charset="UTF-8" action="/line_items" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="0jlRLSkDKi6eM5SSL+3uRB0w2G141KUcJKuy4Bg2YNo="></div>
                            <input id="ART" name="ART" type="hidden" value="9x6mdLbW2aMaHqFK32kZwHWnWA7n0GBp/jXS8KeECsTS+78ytG0SQzFpVODplws5iHm6B6SkZzi3ej2+zpW8iQ==--RNoUUgcZu7MLU8BHJ4ynSQ==">
                            <input id="price" name="price" type="hidden" value="VqatEYzkPEf3P9Y/jNY9Zg==--Iw5nQDqjK9vvZX/RecD1eA==">
                            <input id="distributor_id" name="distributor_id" type="hidden" value="6">
                            <input id="waittime" name="waittime" type="hidden" value="1">
                            <input class="qnt_to_cart" id="cart_quantity" name="cart_quantity" pattern="0|[1-9]\d{0,2}" required="required" type="text" value="1">
                            <input class="orange-button to-cart" name="commit" type="submit" value="В корзину">
                    </form>
                  </td>
                </tr><tr class="zebra-stripe zebra-grey zebra1 even">
                  <td>
                    <h5>
                      Knecht
                    </h5>
                  </td>
                  <td>
                    <h4>
                      OC90
                    </h4>
                  </td>
                  <td style="max-width: 300px;">
                    Фильтр масляный OPEL/GM/DAEWOO
                    Фильтр масляный OPEL/GM/DAEWOO
                  </td>
                  <td>
                  </td>
                  <td>
                    6142
                  </td>
                  <td>
                    1000
                  </td>
                  <td>
                    3
                  </td>
                  <td id="to_cart_and_qnt_td">


                    <form accept-charset="UTF-8" action="/line_items" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="0jlRLSkDKi6eM5SSL+3uRB0w2G141KUcJKuy4Bg2YNo="></div>
                            <input id="ART" name="ART" type="hidden" value="NqgWSvcdv0FEQkjcJZp98gIYe20Fjol8Bn31tB/CjWnTFVsa3J3hmldO1RSqS/pNUcVZ5dh0wcP7YeZxPAkQc4DEPKy7EVuTpMw3oQw58T0=--/XCn0hP3w0mglJ1vTXSjHw==">

                            <input id="price" name="price" type="hidden" value="mFPLSHh7AdEMpQJiZHFKNg==--hfJQGWhjBoD6mNAetXZ3Xw==">
                            <input id="distributor_id" name="distributor_id" type="hidden" value="6">
                            <input id="waittime" name="waittime" type="hidden" value="3">
                            <input class="qnt_to_cart2" id="OC90" name="cart_quantity" pattern="0|[1-9]\d{0,2}" required="required" type="text" value="1">
                            <input class="orange-button to-cart_no" id="OC90" name="commit" type="submit" value="В корзину">
                    </form>
                  </td>
                </tr></tbody>
            </table>

And the jQuery code is

var seen = {};
    $('table tr').each(function() {
        var tr = $(this).clone();
        if(tr.not(':input')){
            if(tr.not('a.details-link')){
                tr.find("td:eq(7)").remove();
                tr.find("td:eq(3)").remove(); 
               // tr.find("td:eq(2)").remove();
                var txt = tr.text().toLowerCase().replace(/\s+/g, '');;        
                if (seen[txt])
                    $(this).remove();
                else
                    seen[txt] = true;
            }
        }
    });

An functional example is here

Community
  • 1
  • 1
Jefferson
  • 794
  • 10
  • 24
  • hm.... to complicated for my table: https://dl.dropbox.com/u/59666091/table.png i need that this two Knecht oc90 gave only one row, becouse first and second columns are same third could be different, and delete not such, where i have buttons (fourth td), also other are same (pricem quantity....) my table: http://jsfiddle.net/zvKSc/ ...Just delete if first second, and columns with price are same, but delete such, where i didn't have buttons... – brabertaser19 Jan 31 '13 at 22:51
  • does 5th and 6th the other columns with values?, and if the row has buttons don't delete the row? – Jefferson Jan 31 '13 at 23:02
  • yes, 6,7,8,9 colums are with values, and if the rows are same than delete duplicate, but leave that, which in 4-th column has buttons.... as in image – brabertaser19 Jan 31 '13 at 23:12
  • according to my image (let's talk just about two knecht's) as result row i wanna see second, with KNECHT OC 90 МАсл.... – brabertaser19 Jan 31 '13 at 23:16
  • In the case of the two knecht's, you only want to keep the second, because this one has the buttons, so in case you have buttons on 4th column don't delete that row. Am I right?, If I'm so the jQuery code, has to be modify to evaluate if there is a button, in that case, it doesn't compare if has to delete. – Jefferson Feb 01 '13 at 03:18
  • so how to solve than? didn't understand on 100% yours last answer.... you understand it right – brabertaser19 Feb 01 '13 at 09:51
  • I updated the answer, please checked, For me is too difficult manage your [fiddle](http://jsfiddle.net/zvKSc/) because I speak/read your language. I added a button on the table, and then it deletes the the other repeat rows. who don't have the button, I don't know if I'm right with this. – Jefferson Feb 01 '13 at 18:58
  • in log's i see 'here'... but nothing happens... also i try var txt = tr.text().toLowerCase().replace(/\s+/g, ''); – brabertaser19 Feb 01 '13 at 20:51
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/23808/discussion-between-jeff-and-brabertaser1992) – Jefferson Feb 01 '13 at 21:22