How can I remove all rows from a table except rows where first TD value is equal to “Revisions Requ

Discussion in 'jQuery' started by asifakhtar, Nov 14, 2022.

  1. #1
    //Code that I have tried but it doesnt work:
    $('#historyOfStatus table td').not(':contains("Revisions Required – CM")').parents("tr").remove();

    <div id="historyOfStatus">
    <table>
    <tbody>
    <tr>
    <th>Value</th>
    <th>Date Time</th>
    <th>By</th>
    </tr>
    <tr>
    <td class="Data1">Draft</td>
    <td class="Data1">2022-11-14 13:34:31</td>
    <td class="Data1">Muhammad Akhtar</td>
    </tr>
    <tr>
    <td class="Data1">Revisions Required – CM</td>
    <td class="Data1">2022-11-14 13:40:18</td>
    <td class="Data1">a</td>
    </tr>
    <tr>
    <td class="Data2">Under CFF Contracts Manager Review</td>
    <td class="Data2">2022-11-14 13:41:38</td>
    <td class="Data2">aa</td>
    </tr>
    <tr>
    <td class="Data1">Under CFF Compliance Review</td>
    <td class="Data1">2022-11-14 13:41:43</td>
    <td class="Data1">aaaa</td>
    </tr>
    <tr>
    <td class="Data2">Revisions Required – CM</td>
    <td class="Data2">2022-11-14 13:41:48</td>
    <td class="Data2">bb</td>
    </tr>
    <tr>
    <td class="Data2">Revisions Required – CM</td>
    <td class="Data2">2022-11-14 13:43:10</td>
    <td class="Data2">cc</td>
    </tr>
    </tbody>
    </table>
    </div>
     
    asifakhtar, Nov 14, 2022 IP
  2. adSellerMarketing

    adSellerMarketing Peon

    Messages:
    10
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    3
    #2
    https://jsfiddle.net/Lvgb6r3f/3/
    $(document).ready(function() {
    $("td:contains('Revisions Required – CM')").css("color", "red");
    $("td:contains('Revisions Required – CM')").parent().remove()
    });
     
    adSellerMarketing, Nov 17, 2022 IP
  3. asifakhtar

    asifakhtar Active Member

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #3
    Thanks for the reply but my Post is:
    How can I remove all rows from a table except rows where first cell value contains "Revisions Required – CM"?
     
    asifakhtar, Nov 17, 2022 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,803
    Likes Received:
    4,534
    Best Answers:
    123
    Trophy Points:
    665
    #4
    I'd just get a list of all the rows and use a for loop to check them and delete.

    Better still, I'd fix it on the server side so it never even hits the page, that way pagination etc will work better.
     
    sarahk, Nov 17, 2022 IP
  5. adSellerMarketing

    adSellerMarketing Peon

    Messages:
    10
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    3
    #5
    This is what it does, it removes tr where that value is present. It's pretty much this line of code $("td:contains('Revisions Required – CM')").parent().remove(). Check this fiddle: https://jsfiddle.net/Lvgb6r3f/3/.
     
    adSellerMarketing, Nov 17, 2022 IP
  6. asifakhtar

    asifakhtar Active Member

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #6
    except rows where first cell value contains "Revisions Required – CM"
     
    asifakhtar, Nov 17, 2022 IP
  7. adSellerMarketing

    adSellerMarketing Peon

    Messages:
    10
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    3
    #7
    Sorry:

    text = "Revisions Required – CM";
    $('table tr:gt(0)').each(function() {
    if ($('td:contains("'+text+'")', this).length == 0) $(this).remove();
    });

    https://jsfiddle.net/k0ybwv3x/1/
     
    adSellerMarketing, Nov 19, 2022 IP
  8. asifakhtar

    asifakhtar Active Member

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #8
    Txs for your reply.

    Hey, your code doesn't work, your code doesn't remove tr if first cell value contains "aaa".
    Anyways I was looking for the following code:
    $('#revisionsRequesteHistory table tr').each(function() {
    if($(this).find('td').first().text() !== 'Revisions Required – CM')
    this.remove();
    });
     
    asifakhtar, Nov 19, 2022 IP
  9. adSellerMarketing

    adSellerMarketing Peon

    Messages:
    10
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    3
    #9
    You said to remove the rows other than Revisions Required -CM
     
    adSellerMarketing, Nov 20, 2022 IP