2013-02-20 2 views
0

약간의 문제가있는 것 같고 누군가 나를 도와 줄 수 있습니다.js 또는 jQuery를 통해 요청시 테이블 형식 데이터 표시/숨기기

DB에서 데이터를 가져 오지 않으면 표 행/열을 숨기는 것입니다. 또는 존재하지 않을 수도 있습니다 및 I/열을 해당 행을 숨길 필요 -

<div style="border: 1px solid #ccc;"> 

    <table class="tableizer-table"> 
    <tr> 
     <td class="first-row" colspan="2"># Of Items in Package: <?php echo $_product->getItemsInPackage(); ?></td> 
    </tr> 
    <tr> 
     <td class="second-row">Size Scale</td> 
     <td class="second-row">Quantity</td> 
    </tr> 
    <tr> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_size_1') ?></td> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_quantity_one') ?></td> 
    </tr> 
    <tr> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_size_2') ?></td> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_quantity_two') ?></td> 
    </tr> 
    <tr> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_size_3') ?></td> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_quantity_three') ?></td> 
    </tr> 
     <tr> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_size_4') ?></td> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_quantity_four') ?></td> 
    </tr> 
    <tr> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_size_5') ?></td> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_quantity_five') ?></td> 
    </tr> 
    <tr> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_size_6') ?></td> 
     <td class="cell" style="empty-cells:hide; border-collapse: separate;"><?php echo $_product->getAttributeText('bundle_quantity_six') ?></td> 
    </tr> 
    </table> 
</div> 
기본적으로

, bundle_size_5 & bundle_size_6 (다른 사람들이) : 나는 다소 다음 코드를 사용하여이 작업을 수행 할 수 있었다. 하지만 나는 CSS (테두리 예제)로 스타일을 지정하고 숨겨져 있음에도 불구하고 예약 된 공간이 그대로 있고 경계가 주변에 있다는 것을 알아 차렸습니다.

js 또는 jQuery를 통해 데이터가 없으면 해당 행/열을 완전히 숨길 수 있습니까?

답변

0

시도,

$(document).ready(function() { 
$('.tableizer-table tr').each(function() { 
    var t = $(this).find('td'); 
    if (t.text() === '') { 
    t.css('borderLeft','0px'); //or border-left 
    t.hide(); 
    } 
    }); 
}); 
재산 borderLeft에 대한

Demo

Manual

, 그리고 '경계'.

+0

코드를 적게 사용하는 방법이 있습니다. 시도 할 때주의해야합니다. 모든 경우에 작동하지 않을 수 있습니다. http://jsfiddle.net/Ccwpm/ – gustavohenke

+0

코드를 보내 주셔서 감사합니다. 그러나 저에게 맞지 않는 것 같습니다. . 이것은 내 코드 (이미지)에 적용하면 다음과 같습니다. http://imgur.com/VCOGOHI - 회색 경계선은 셀이 숨어있는 공백을 계속 돌아 다니고 있습니다. –

관련 문제