Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to create a table with indents from nested JSON in angularjs

angular.module('app').controller('RootCtrl', ['$scope', function($scope) {
    // assigning the data to $scope to make it available in the view
    $scope.tableData = {Example Data from top};
}]);

//Your tree component could be something on this lines:

angular.module('app').component('treeComponent', {
    controller: 'TreeCtrl',
    bindings: {
        tree: '<',
    },
    templateUrl: 'tree-view.html'
});

//your root template should load the first instance of the component:

<div>
   <tree-component tree="tableData"></tree-component>
</div>

//then the component template should take care of the the recursion when required; tree-view.html:

<table class="record-table">
    <thead>
        <tr>
           <th>
              <strong>{{ $ctrl.tableData.name }}</strong>
           </th> 
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="node in $ctrl.tableData.children">
            <td>{{node.name}}</td>
            <td ng-if="node.children.length > 0">
               <tree-component tree="node.children"></tree-component>
            </td>
        </tr>
    </tbody>
</table>

//creating indentation then becomes easy using basic css:

.record-table .record-table {
   padding-left: 20px
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: angularjs How can I write below code in better way to keep looping endlessly 
Javascript :: Display name instead ID modal dropdown in angularjs 
Javascript :: angularjs Re-evalute expressions when page reloads via history 
Javascript :: angularjs Prevent from getting rendered 
Javascript :: AngularJS SPA edit button function 
Javascript :: Angularjs $on called twice 
Javascript :: Angular after click add active class and remove from siblings 
Javascript :: Porting Promise.all functionality from AngularJs to VueJs 
Javascript :: how to use recursive function to select the parent in a tree array using angulat ui tree 
Javascript :: How to query a button with specific text with react native testing library 
Javascript :: Syntax for npx 
Javascript :: how to make colspan of table footer flexible with javascript/jQuery 
Javascript :: arrow function - one line and no parameters 
Javascript :: get the character code in a string 
Javascript :: Pass 3 of the same thing to ExpressJS with a form 
Javascript :: get copied text javascript 
Javascript :: useEffect in React 18 in strictmode 
Javascript :: iterate over element parent jquery 
Javascript :: function x(a) vs function x(...a) the difference 
Javascript :: Setting Multiples Properties With Array 
Javascript :: Create Nodejs logger that does not replace file when app/server restarts 
Javascript :: underscore js filter array of objects 
Javascript :: React Native - iOS Release build crashing 
Javascript :: cubing timer 
Javascript :: Hardhat config file multiple network 
Javascript :: json to dart dummy api 
Javascript :: wp include js 
Javascript :: Backbone Collection 
Javascript :: Check if a number starts with another number or not js 
Javascript :: use strict print this 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =