in Education by
I need to make a table with data with nested subtasks. I need to make this table recursive. There is a lot of literature about ngFor recursively showing data, but not in a table format. There are a lot of things that make tables harder to work with(e.g. using div tags outside of td tags, etc.) here is a stackblitz of what I got so far. https://stackblitz.com/edit/angular-xk9nw6?file=src%2Fapp%2Ftable%2Ftable.component.html As you can see, I can only drill down a single level before I encounter issues with ngFor

Table

table{ background:rgb(223, 221, 221); } {{subtask?.taskID}} {{subtask?.taskName}} Add Edit Delete
expand task id task name button
{{datum.taskID}} {{datum.taskName}} <!-- <i class="fas fa-ellipsis-h" data-toggle="dropdown"> -->
{{subtaskL?.taskID}} {{subtaskL?.taskName}}
component import { Component, OnInit,ViewChild } from '@angular/core'; import { sampleData } from '../datasource'; @Component({ selector: 'app-table', templateUrl: './table.component.html', styleUrls: ['./table.component.css'] }) export class TableComponent implements OnInit { constructor() { } @ViewChild('treegrid') public data: Object[]; public foo: boolean; public subtaskArray: any; public subSubtaskArray: any; public index: number; dropdown(e){ console.log(e); } task(e, i){ console.log(e); this.subtaskArray = e.subtasks this.index = i; } subtaskQ(e, j){ this.subSubtaskArray = e.subtasks; console.log(j); console.log(e); } switch(){ if(this.foo){ this.foo =false; } else { this.foo = true; } } ngOnInit(): void { this.data = sampleData; } } sample data /** * Test cases data source */ export let sampleData: Object[] = [ { taskID: 1, taskName: 'Planning', startDate: new Date('02/03/2017'), endDate: new Date('02/07/2017'), progress: 100, duration: 5, priority: 'Normal', approved: false, isInExpandState: true, subtasks: [ { taskID: 2, taskName: 'Plan timeline', startDate: new Date('02/03/2017'), endDate: new Date('02/07/2017'), duration: 5, progress: 100, priority: 'Normal', approved: false }, { taskID: 3, taskName: 'Plan budget', startDate: new Date('02/03/2017'), endDate: new Date('02/07/2017'), duration: 5, progress: 100, approved: true }, { taskID: 4, taskName: 'Allocate resources', startDate: new Date('02/03/2017'), endDate: new Date('02/07/2017'), duration: 5, progress: 100, priority: 'Critical', approved: false }, { taskID: 5, taskName: 'Planning complete', startDate: new Date('02/07/2017'), endDate: new Date('02/07/2017'), duration: 0, progress: 0, priority: 'Low', approved: true } ] }, { taskID: 6, taskName: 'Design', startDate: new Date('02/10/2017'), endDate: new Date('02/14/2017'), duration: 3, progress: 86, priority: 'High', isInExpandState: false, approved: false, subtasks: [ { taskID: 7, taskName: 'Software Specification', startDate: new Date('02/10/2017'), endDate: new Date('02/12/2017'), duration: 3, progress: 60, priority: 'Normal', approved: false }, { taskID: 8, taskName: 'Develop prototype', startDate: new Date('02/10/2017'), endDate: new Date('02/12/2017'), duration: 3, progress: 100, priority: 'Critical', approved: false }, { taskID: 9, taskName: 'Get approval from customer', startDate: new Date('02/13/2017'), endDate: new Date('02/14/2017'), duration: 2, progress: 100, approved: true }, { taskID: 10, taskName: 'Design Documentation', startDate: new Date('02/13/2017'), endDate: new Date('02/14/2017'), duration: 2, progress: 100, approved: true }, { taskID: 11, taskName: 'Design complete', startDate: new Date('02/14/2017'), endDate: new Date('02/14/2017'), duration: 0, progress: 0, priority: 'Normal', approved: true } ] }, { taskID: 12, taskName: 'Implementation Phase', startDate: new Date('02/17/2017'), endDate: new Date('02/27/2017'), priority: 'Normal', approved: false, duration: 11, subtasks: [ { taskID: 13, taskName: 'Phase 1', startDate: new Date('02/17/2017'), endDate: new Date('02/27/2017'), priority: 'High', approved: false, duration: 11, subtasks: [{ taskID: 14, taskName: 'Implementation Module 1', startDate: new Date('02/17/2017'), endDate: new Date('02/27/2017'), priority: 'Normal', duration: 11, approved: false, subtasks: [ { taskID: 15, taskName: 'Development Task 1', startDate: new Date('02/17/2017'), endDate: new Date('02/19/2017'), duration: 3, progress: '50', priority: 'High', approved: false }, { taskID: 16, taskName: 'Development Task 2', startDate: new Date('02/17/2017'), endDate: new Date('02/19/2017'), duration: 3, progress: '50', priority: 'Low', approved: true }, { taskID: 17, taskName: 'Testing', startDate: new Date('02/20/2017'), endDate: new Date('02/21/2017'), duration: 2, progress: '0', priority: 'Normal', approved: true }, { taskID: 18, taskName: 'Bug fix', startDate: new Date('02/24/2017'), endDate: new Date('02/25/2017'), duration: 2, progress: '0', priority: 'Critical', approved: false }, { taskID: 19, taskName: 'Customer review meeting', startDate: new Date('02/26/2017'), endDate: new Date('02/27/2017'), duration: 2, progress: '0', priority: 'High', approved: false }, { taskID: 20, taskName: 'Phase 1 complete', startDate: new Date('02/27/2017'), endDate: new Date('02/27/2017'), duration: 0, priority: 'Low', approved: true } ] }] }, { taskID: 21, taskName: 'Phase 2', startDate: new Date('02/17/2017'), endDate: new Date('02/28/2017'), priority: 'High', approved: false, duration: 12, subtasks: [{ taskID: 22, taskName: 'Implementation Module 2', startDate: new Date('02/17/2017'), endDate: new Date('02/28/2017'), priority: 'Critical', approved: false, duration: 12, subtasks: [ { taskID: 23, taskName: 'Development Task 1', startDate: new Date('02/17/2017'), endDate: new Date('02/20/2017'), duration: 4, progress: '50', priority: 'Normal', approved: true }, { taskID: 24, taskName: 'Development Task 2', startDate: new Date('02/17/2017'), endDate: new Date('02/20/2017'), duration: 4, progress: '50', priority: 'Critical', approved: true }, { taskID: 25, taskName: 'Testing', startDate: new Date('02/21/2017'), endDate: new Date('02/24/2017'), duration: 2, progress: '0', priority: 'High', approved: false }, { taskID: 26, taskName: 'Bug fix', startDate: new Date('02/25/2017'), endDate: new Date('02/26/2017'), duration: 2, progress: '0', priority: 'Low', approved: false }, { taskID: 27, taskName: 'Customer review meeting', startDate: new Date('02/27/2017'), endDate: new Date('02/28/2017'), duration: 2, progress: '0', priority: 'Critical', approved: true }, { taskID: 28, taskName: 'Phase 2 complete', startDate: new Date('02/28/2017'), endDate: new Date('02/28/2017'), duration: 0, priority: 'Normal', approved: false } ] }] }, { taskID: 29, taskName: 'Phase 3', startDate: new Date('02/17/2017'), endDate: new Date('02/27/2017'), priority: 'Normal', approved: false, duration: 11, subtasks: [{ taskID: 30, taskName: 'Implementation Module 3', startDate: new Date('02/17/2017'), endDate: new Date('02/27/2017'), priority: 'High', approved: false, duration: 11, subtasks: [ { taskID: 31, taskName: 'Development Task 1', startDate: new Date('02/17/2017'), endDate: new Date('02/19/2017'), duration: 3, progress: '50', priority: 'Low', approved: true }, { taskID: 32, taskName: 'Development Task 2', startDate: new Date('02/17/2017'), endDate: new Date('02/19/2017'), duration: 3, progress: '50', priority: 'Normal', approved: false }, { taskID: 33, taskName: 'Testing', startDate: new Date('02/20/2017'), endDate: new Date('02/21/2017'), duration: 2, progress: '0', priority: 'Critical', approved: true }, { taskID: 34, taskName: 'Bug fix', startDate: new Date('02/24/2017'), endDate: new Date('02/25/2017'), duration: 2, progress: '0', priority: 'High', approved: false }, { taskID: 35, taskName: 'Customer review meeting', startDate: new Date('02/26/2017'), endDate: new Date('02/27/2017'), duration: 2, progress: '0', priority: 'Normal', approved: true }, { taskID: 36, taskName: 'Phase 3 complete', startDate: new Date('02/27/2017'), endDate: new Date('02/27/2017'), duration: 0, priority: 'Critical', approved: false }, ] }] } ] } ]; I am hoping to achieve a table that handles data recursively, placing subtasks under their parent tasks, and sub-sub-tasks under their parent subtasks, etc, etc. currently, I can only drill down one level in with non dynamic markup. there are plenty of examples of how this works with unordered lists, but these methods don't seem to work with tables as well. dropping a selector tag on inside it's own markup causes issues. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
A recursive component it's only make a component like @Component({ selector: 'recursive-component', template:` {{index}}--some template--, e.g {{item.title}} ` }) export class MenuComponent { @Input() item:any @Input() index:number=0; } I like know the "level of recursion" it's the reason of this "index". WE must use to avoid create extra html tags, and take a look too, that we must feed the component with an object with children, so. if we has an array, like items = [{ title: "item1" }, { title: "item2", children: [ { title: "item 2.1" }, { title: "item 2.2" }] }, { title: "item3" } ] We can create "on fly" an object with children and our .html will be But you can not do using tables, because always you'll get a table inside another table or a tr inside another tr If you need use table you can take another aproach: generate an array based in your data and if is expanded or not. So, you can do a function like getItems(data, items,index) { data.forEach(x => { if (!items) items=[]; items.push(x); items[items.length-1].index=index if (x.subtasks && x.expanded) this.getItems(x.subtasks,items,index+1); } ) return items; } Then you can simple //In your .html
{{item.taskID}} {{item.taskName}}
//And in your .ts ngOnInit() { this.items=this.getItems(this.sampleData,null,0) } expanded(item:any) { item.expanded=!item.expanded; this.items=this.getItems(this.sampleData,null,0) } In stackblitz, you can see the two options NOTE: I simple use div (click) or tr (click) to change the "expanded" property. NOTE2: In the stackblitz I use the "index" to change the margin or the padding of the elements

Related questions

0 votes
    How can I check the file going to be written exists in the directory, and if not , How can I create directory ... " flag for the same? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    How can I safely create a nested directory?...
asked Jan 9, 2021 in Technology by JackTerrance
0 votes
    By default, Writer evalutes ______ levels of headings when it builds the table of contents Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    Fifteen persons, among whom are A and B, sit down at random on a round table. The probability that there are 4 ... ! D. none of these Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    Create a nested list as follows using both ordered and unordered list tags: 1. Operating System o Disk operating ... Unix o Linux Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    SA=1000.00 AI=0.12 MP=100.00 def remainb(x): if x==0: return 0 else: return x=(SA+(AI/12)*SA)-MP for ... . run the loop until SA==0). Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Write C program that use both recursive and non recursive functions to perform Linear search for a Key value in a given list. Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
0 votes
    Give scientific reasons: We can see biodiversity on three levels. Select the correct answer from above ... proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    What are the different levels at which performance improvement can be performed in Informatica?...
asked Mar 27, 2021 in Technology by JackTerrance
0 votes
    _______________ are the supported data types in Apache Drill. Please select the correct options from below (a)BINARY (b)DATE (c)BIGINT (d)All of the options...
asked Dec 11, 2020 in Education by Editorial Staff
0 votes
    Drill assigns each _________ fragment with a MajorFragmentID a)minor b)None of the options c)major d)All of the options...
asked Dec 11, 2020 in Education by Editorial Staff
0 votes
    When a query is submitted in Drill, client/application sends the query in the form of an _____________ to Drillbit in a ... of the options c)None of the options d)NoSQL statement...
asked Dec 11, 2020 in Education by Editorial Staff
0 votes
    Apache Drill has a high latency distributed query engine for analyzing small-scale datasets. (1)False (2)True...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    Name the following: 1. Levels in the food chain. 2. Organisms that decompose the dead bodies of ... ,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
...