A guide on effectively utilizing nested arrays within a pcolumn prime ng data table

I have a nested array structure and I am utilizing PrimeNG data table to display the data. Below is the organization of my array:

this.institutionalTimetable = [
{day: "Monday", entries: [{startTime: "132", endTime: "789", recess: true, subject: 'English', subjectGroup:'Maths' }, {startTime: "582", endTime: "634", recess: true, subject: 'English' , subjectGroup: 'Maths'}]},
{day: "Tuesday", entries: [{startTime: "132", endTime: "789", recess: true, subject: 'English', subjectGroup:'Maths' }, {startTime: "582", endTime: "634", recess: true, subject: 'English' , subjectGroup: 'Maths'}, {startTime: "582", endTime: "634", recess: true, subject: 'English' , subjectGroup: 'Maths'}]},
{day: "Wednesday", entries: [{startTime: "132", endTime: "789", recess: true, subject: 'English', subjectGroup:'Maths' }, {startTime: "582", endTime: "634", recess: true, subject: 'English' , subjectGroup: 'Maths'}]}

]

The table structure should list the days in the first column with multiple columns for the entries within each day.

How can I create a <p-column> for each entry within the main array?

This is what I attempted:

<p-dataTable [value]="institutionalTimetable" class="institutetable" >
  <p-headerColumnGroup >
    <p-row>
      <p-column header="Week Days"></p-column>
      <p-column header="Time table" [colspan]="10"></p-column>
    </p-row>
  </p-headerColumnGroup>
  <p-column field="day"></p-column>
  <p-column field="entries" *ngFor="let entrys of entries">
    <ng-template let-col let-entryData="rowData" pTemplate="body">
     
      <span>{{ entrys.startTime }}</span>

    </ng-template>
  </p-column>
</p-dataTable>

Answer №1

I believe I have a good grasp of your requirements.

If I were in your shoes, I would suggest recreating an array by iterating through each day and entry in the institutionalTimetable.

Subsequently, you could create a straightforward dataTable structured like this:

<p-dataTable [value]="institutionalTimetable2" class="institutetable" >
  <p-headerColumnGroup >
    <p-row>
      <p-column header="Week Days"></p-column>
      <p-column header="Time table" [colspan]="5"></p-column>
    </p-row>
  </p-headerColumnGroup>
  <p-column field="day"></p-column>
  <p-column field="startTime"></p-column>
  <p-column field="endTime"></p-column>
  <p-column field="recess"></p-column>
  <p-column field="subject"></p-column>
  <p-column field="subjectGroup"></p-column>
</p-dataTable>

Feel free to check out my Plunker example

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling to align my image in the center while applying a hover effect using CSS

Hey there, I'm having an issue centering my image when I add instructions for it to tilt on mouseover. If I take out the 'tilt pic' div, the image centers just fine. Can anyone help me identify what I might be doing wrong? Thanks in advance! ...

Nextjs 14 experiences full page loading due to the presence of multiple root layouts

The issue I'm facing involves a full page load when navigating between two root layout pages In my Next.js application (NextJS 14), I have created two root layouts. However, when moving from the first layout to the second layout, it triggers a comple ...

What is the method for retrieving a variable from a Q Node promise?

I am currently developing a learning game utilizing Angular, Express, MongoDB, and Node. As part of my learning process, I have been exploring the use of promises to manage asynchronous operations effectively. One particular challenge I am facing involves ...

The EJS view fails to render when called using the fetch API

Within my client-side JavaScript, I have implemented the following function which is executed upon an onclick event: function submitForm(event) { const data = { name, image_url }; console.log(data); fetch('/', { method: &apo ...

Having trouble deploying an Angular Universal app to an AWS S3 bucket with server-side rendering (SSR

Transitioning from an Angular9 application to make it SEO friendly required me to switch to Angular Universal SSR. I followed the steps below: Ran the command: ng add @nguniversal/express-engine Ran the command: npm run dev:ssr Ran the command: npm run bu ...

Having trouble setting up jQuery UI Datepicker in my system

I am attempting to add a datepicker to my website, but it is not showing up in the browser. Could there be an issue with some of the other script files I have? Below is where my datepicker div is located: <body> <!-- Preloader --> <div id= ...

What is the most effective way to transform values into different values using TypeScript?

If I have a list of country codes and I want to display the corresponding country names in my component, how can I achieve this using props? interface MyComponentProps { countryCode: 'en' | 'de' | 'fr'; } const MyComponent: ...

Discovering the data type from its textual representation

Is it possible for TypeScript to automatically determine the generic argument of assertTypeof based on the value of expectedType? I am looking for a way to use the function below without having to specify number multiple times. playable example type Typ ...

Implementing momentLocalizer with moment.js in react-big-calendar alongside fullcalendar.js

I'm currently working with react-big-calendar and I require assistance in setting up localization as per the example provided on GitHub. import BigCalendar from 'react-big-calendar'; import moment from 'moment'; BigCalendar.setLo ...

Ways to enlarge a YouTube thumbnail upon loading using JavaScript

I recently found a solution to my question on how to prevent YouTube videos from repeating even when different embedded codes are used. I have a specific need to resize the thumbnail image of my YouTube video to width:146px and height:124px when the page l ...

What steps can be taken to ensure your bot successfully sends the second argument?

Who just handed out an L to user#0000? Looks like JohnGameRage#0000 did! ...

How can one view all the static variables and methods associated with a class in Typescript or ES6?

Is it possible to retrieve all static variable names and static method names associated with a class, similar to how the Object.keys method returns a list of key names attached to an object? Typescript Example: class FindStatics { static num1:string = ...

Is there a notification system that sparkles like a precious Facebook gem

Is there a system similar to Facebook's request, message, and notification bubble system that can alert users on their profiles about new messages or notifications? I know Facebook is very advanced, but if anyone knows of something similar, please let ...

Passing values to the next page is not functioning as expected

I'm having trouble passing a variable called userId to the next page in my application. Below is the snippet of code I am using to pass the value to the next page: $.each($.parseJSON(data), function(key, value) { var userId = value.id_user; ...

Exploring the capabilities of Google Apps Script for looping and generating output

I have two spreadsheets named rawData and processedData. The content of rawData is as follows: Status Title Options Live Title1 Option1, Option2, Option3, Option4 Live Title2 Option1, Option2, Option3, Option4, Option5 Live Title3 Option1, O ...

Update the variable in a PHP script and execute the function once more without the need to refresh the page

Hey there, I'm wondering if AJAX is necessary for the functionality I want to implement. Here's the scenario: I have a function that generates a calendar and I plan to add 'forward' and 'backward' arrows so users can navigate ...

The function toDataURL() in Canvas is storing images in low resolution

I created a unique polygonal background generator using HTML5 canvas which can be found at the following link: http://codepen.io/rfalor/pen/LhinJ Here is the important part of the code: var canvas = document.getElementById("canvas"); var ctx = c ...

Styling array of arrays

When retrieving data from an API, the structure looks like this: "key1" : { "subkey1" : value "subkey2" : value "subkey3" : value } "key2" : { &q ...

Leveraging ZOD's discriminatedUnion() method to differentiate among three different forms

ValidationSchema = z.object({ AuthenticationBlock: z.object({ ChoiceOfForm: z.enum() DataBlock: z.discriminatedUnion(ChoiceOfForm, [ z.object({ ChoiceOfForm = 1, empty fields}) //corresponds to the basic form z.object({ ChoiceOfForm = 2, just ...

Components that rely on Angular's properties

I currently have three main components in my project: CategoryComponent - responsible for displaying a list of categories ListComponent - displays elements based on the selected category ScreenComponent - combines MenuComponent and ContentComponent toget ...