Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

View Tree Collapse and Expand Mode : Tree View Collapse and Expand Mode

The markup used is html table.

Using ng-repeat is getting tricky.

The data for each row is as below

{ "id":1,"name":"Groceries","price":"0","total":"20","parentFlag":"true","parentId":"",childItems :[{},{}] }

Using ul,li tags we can achieve this using ng-include.

But existing app markup uses table. I am starting to think changing the markup to use ul,li, div is the "only" way to go. Am I missing something here. Any pointers/approaches ??

share|improve this question
1  
Can you supply some code & view markup? Preferably throw together a minimally functional example on jsFiddle or Plunker. It's hard to understand what your goals are and your current issue is without more information. – OverZealous Aug 2 '13 at 1:24

you can try something like:

<table class="table">
    <thead>
        <tr>
            <th>Package</th>
            <th>Price</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat-start='Package in Packages'>
            <!-- take a look to ng-repeat-start -->
            <td>
                <button ng-click="viewChilds= !viewChilds">+</button>{{Package.name}}</td>
            <td>{{Package.total}}</td>
        </tr>
        <tr>
            <!-- this is repeated for package-->
            <td colspan='2' ng-class="viewChilds? '' : 'hide'">
                <!-- viewChilds controls the collapse () -->
                <table class="subTable">
                    <!-- make some ident in subTable style -->
                    <tbody>
                        <tr ng-repeat='chilItem in Package.childItems'>
                            <!-- a nested repeat for each children -->
                            <td>{{chilItem.name}}</td>
                            <td>{{chilItem.price}}</td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
        <tr ng-repeat-end></tr>
        <!-- this is repeated also (if you need) -->

    </tbody>
</table>

i spect that you can figure it out, dont forget to show the final work

here is a plunker: http://plnkr.co/edit/ENXYcu?p=preview

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.