2017-08-25 54 views
2

我開始編碼了。我正在使用Symfony 3.3 我想用複選框隱藏(並顯示)表格上的一個或一些特定行。 我嘗試使用JavaScript和jQuery。我希望隱藏的行保持隱藏狀態。 我不知道該怎麼做。這裏是我的樹枝用symfony隱藏表格行(0123)

{% block body %} 

    <div class="container"> 
     <h3>List of products</h3> 

     <table class="table table-striped"> 
    <thead> 
    <tr> 
     <th>Product</th> 
     <th>Description</th> 
     <th>Size</th> 
     <th>Charges</th> 
     <th>Price</th> 
     <th>Actions</th> 
     <th>Desactivation</th> 

    </tr> 
    </thead> 

    <tbody> 
    {% for catalogue in catalogues %} 
    <tr class="table"> 

     <td>{{ catalogue.product}} </td> 
     <td>{{ catalogue.description }} </td> 
     <td>{{ catalogue.size}} </td> 
     <td>{{ catalogue.charge }} </td> 
     <td>{{ catalogue.price }}</td> 
     <td> 
      <a href="{{ path('catalogue_list_edit', { 'id': catalogue.id }) }}"><span class="glyphicon glyphicon-edit"></span></a> 
      <a href="{{ path('catalogue_list_delete', { 'id': catalogue.id }) }}"><span class="glyphicon glyphicon-remove"></span></a> 
     </td> 
      <td><input type="checkbox" name="boutton35" value="Desactivation" /> 
     </td> 

    </tr> 

    {% else %} 
    {% endfor %} 

    </tbody> 
     </table> 

{% endblock %} 
+0

對不起,我看錯。如果複選框位於隱藏行內,你如何顯示隱藏行 –

+0

我想他想用複選框進行「切換」並隱藏一些元素。你想隱藏整行或只是一些​​? – SD3L

+0

直到我再次點擊複選框! \t 整行! \t 我想我需要我所有產品的ID?但我不知道如何恢復它們。複選框可以留下?或者我不知道...一個按鈕顯示所有的按鈕隱藏也許? – Koila69

回答

0

$('.hideshow').on('click',function(){ 
 
    let cls = $(this).attr("data-id") 
 
    if ($('#'+cls).css('display') == 'none'){ 
 
    $('.table tbody').find('#'+cls).show(); 
 
    }else{ 
 
    $('.table tbody').find('#'+cls).hide(); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 

 
<div class="container"> 
 
    <h3>List of products</h3> 
 

 
    <div class="buttons"> 
 
    <button type="button" data-id="tr1" class="hideshow">Hide/Show Row 1</button> 
 
    <button type="button" data-id="tr2" class="hideshow">Hide/Show Row 2</button> 
 
    <button type="button" data-id="tr3" class="hideshow">Hide/Show Row 3</button> 
 
    </div> 
 
    <table class="table table-striped"> 
 
    <thead> 
 
     <tr> 
 
     <th>Product</th> 
 
     <th>Description</th> 
 
     <th>Size</th> 
 
     <th>Charges</th> 
 
     <th>Price</th> 
 
     <th>Actions</th> 
 
     <th>Desactivation</th> 
 
     </tr> 
 
    </thead> 
 

 
    <tbody> 
 
     <tr id="tr1"> 
 
     <td>Product </td> 
 
     <td>Description </td> 
 
     <td>Size </td> 
 
     <td>Charges </td> 
 
     <td>Price</td> 
 
     <td> 
 
      <a href="#">Edit</a> 
 
      <a href="#">Remove</a> 
 
     </td> 
 
     <td><input type="checkbox" name="boutton35" value="Desactivation" /> 
 
     </td> 
 
     </tr> 
 
     <tr id="tr2"> 
 
     <td>Product </td> 
 
     <td>Description </td> 
 
     <td>Size </td> 
 
     <td>Charges </td> 
 
     <td>Price</td> 
 
     <td> 
 
      <a href="#">Edit</a> 
 
      <a href="#">Remove</a> 
 
     </td> 
 
     <td><input type="checkbox" name="boutton35" value="Desactivation" /> 
 
     </td> 
 
     </tr> 
 
     <tr id="tr3"> 
 
     <td>Product </td> 
 
     <td>Description </td> 
 
     <td>Size </td> 
 
     <td>Charges </td> 
 
     <td>Price</td> 
 
     <td> 
 
      <a href="#">Edit</a> 
 
      <a href="#">Remove</a> 
 
     </td> 
 
     <td><input type="checkbox" name="boutton35" value="Desactivation" /> 
 
     </td> 
 
     </tr> 
 
    </tbody> 
 
    </table>

+0

這是一個好主意。但是我會有20行,通過我的數據庫生成。我不知道如何爲每個 – Koila69

+0

@ Koila69生成好身份證你是什麼意思?你有你的樹枝圈? '%{catalog for catalogs%}} {%endfor%}和{{目錄%中的目錄%} ... 。 .... {%endfor%}' – DarkBee

+0

它工作的很好!謝謝你們:D – Koila69