2013-10-31 3 views
-1

중첩 트리 테이블에 모두 확장/모두 축소 기능을 적용하려고하는데 원하는 출력이 표시됩니다. 나는 같은 것을 this related question 따라 갔다. 여기에 fiddle입니다. 이미지가 확대 전체 테이블이 숨겨져됩니다 축소를 클릭하지 않고, 나는 모든 TR이 확대를 확장 를 클릭하면모두 확장 모두 축소/트리 테이블이 작동하지 않음 propery?

<a class="myexpand" href="#">Expand</a> | <a class="mycollapse" href="#">Collapse</a> 
<table id="mytable"> 
    <thead> 
     <th class="firstCol">Titulo</th> 
     <th class="LastCol">Valor</th> 
    </thead> 
    <tr data-depth="0" class="collapse level0"> 
     <td><span class="toggle collapse"></span>Item 1</td> 
     <td>123</td> 
    </tr> 
    <tr data-depth="1" class="collapse level1"> 
     <td><span class="toggle"></span>Item 2</td> 
     <td>123</td> 
    </tr> 
    <tr data-depth="2" class="collapse level2"> 
     <td><span class="toggle"></span>Item 3</td> 
     <td>123</td> 
    </tr> 
    <tr data-depth="3" class="collapse level3"> 
     <td>Item x</td> 
     <td>Letra</td> 
    </tr> 
    <tr data-depth="1" class="collapse level1"> 
     <td><span class="toggle"></span>Item 4</td> 
     <td>123</td> 
    </tr> 
    <tr data-depth="2" class="collapse level2"> 
     <td>Item 4x</td> 
     <td>123</td> 
    </tr> 
    <tr data-depth="0" class="collapse collapsable level0"> 
     <td><span class="toggle collapse"></span>Item 5</td> 
     <td>123</td> 
    </tr> 
    <tr data-depth="1" class="collapse collapsable level1"> 
     <td>Item 6</td> 
     <td>123</td> 
    </tr> 
</table> 

SCRIPT


$(function() { 
    $('#mytable').on('click', '.toggle', function() { 
     //Gets all <tr>'s of greater depth 
     //below element in the table 
     var findChildren = function (tr) { 
      var depth = tr.data('depth'); 
      return tr.nextUntil($('tr').filter(function() { 
       return $(this).data('depth') <= depth; 
      })); 
     }; 

     var el = $(this); 
     var tr = el.closest('tr'); //Get <tr> parent of toggle button 
     var children = findChildren(tr); 

     //Remove already collapsed nodes from children so that we don't 
     //make them visible. 
     //(Confused? Remove this code and close Item 2, close Item 1 
     //then open Item 1 again, then you will understand) 
     var subnodes = children.filter('.expand'); 
     subnodes.each(function() { 
      var subnode = $(this); 
      var subnodeChildren = findChildren(subnode); 
      children = children.not(subnodeChildren); 
     }); 

     //Change icon and hide/show children 
     if (tr.hasClass('collapse')) { 
      tr.removeClass('collapse').addClass('expand'); 
      children.hide(); 
     } else { 
      tr.removeClass('expand').addClass('collapse'); 
      children.show(); 
     } 
     return children; 
    }); 
    $('.toggle').trigger('click'); 

    $(".myexpand").click(function() { 
      $("#mytable tr").show("slow"); 
    }); 
    $(".mycollapse").click(function() { 
      $("#mytable tr").hide("fast"); 
    }); 


}); 

문제입니다.

효율적인 방법으로 누군가를 도와 줄 수 있습니까?

미리 감사드립니다.

+0

내 기능에 의해 THEAD

<thead> <tr> <th class="firstCol">Titulo</th> <th class="LastCol">Valor</th> </tr> </thead> 

하고 기능을 대체 내부 그럴 태그가 없습니다 r에? – Arjun

+0

바이올린은 이미 여기에 있습니다. – shemy

+0

나는 이미 위도 링크 mysample js를 확인하시기 바랍니다. – Sukane

답변

1

아래처럼 사용 .... u는 당신이 바이올린을 제공 할 수

$(".mycollapse").click(function() { 
      $("#mytable tr").hide("fast"); 
      $("#mytable thead tr").show("fast"); 
      $("#mytable tr.level0").show("fast"); 
     }); 
+0

위의 솔루션은 축소를 위해 잘 작동하지만 확장을 클릭하면 모든 이미지 더하기 기호가 빼기 (붕괴) 기호로 변경되지 않습니다. – Sukane

+0

이것을 확인하십시오 http://jsfiddle.net/4SZS4/2/ – Sukane

+0

확장 링크를 클릭했을 때 확장 및 축소 이미지를 관리하는 논리를 시도했지만 문제가 있습니다. @Kundan 귀하의 솔루션은 붕괴에 도움이되었고, exapad에 대한 더 많은 정보를 모두 제공 할 수 있습니다. – Sukane