Binding and using an object's fields within an object returned by the server API with a PrimeNG data table












0














Good day



Currently I am returning an array of objects looking like:



{
attendeeCount: 5
bookDay: "2018-11-22T14:06:24.120Z"
bookingComment: "This is a test"
conferenceRoom: {id: 8, name: "Main Boardroom", seatingCount: 10, location: "Site Office", projector: "YES"}
employee: {id: 111, title: "Mr.", initials: "J", preferredName: "John", lastName: "Smith", …}
id: 1
refreshment: {id: 1, name: "Coffee, Tea and Water"}
timeSlot: "07:00 - 07:30"
}


The requirement then is that I should be able to render the PrimeNG data table using TypeScript like the below:



public getRoomRosterTable() {
this.conferenceRoomBookingService.getRoomRoster(this.dateValue, this.selectedConferenceRoom.id).subscribe(response => {
console.warn(response);
this.conferenceRoomBookings = response;
}, error1 => {
this.alertService.error(error1);
});

this.timeSlotCols = [
{field: 'timeSlot', header: 'Time Slot'},
{field: 'employee.preferredName' + 'employee.lastName', header: 'Slot Booked By'},
{field: 'attendeeCount', header: 'Attendee Count'},
{field: 'refreshment.name', header: 'Refreshment Details'},
{field: 'bookingComment', header: 'Booking Comment'}
];
}


Combined with html looking like:



<p-table [value]="conferenceRoomBookings" [reorderableColumns]="true" [columns]="timeSlotCols">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
<div style="text-align:center">
{{col.header}}
</div>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>


This however only renders the columns that have direct data bound. I cannot seem to get the table to pick up properties of nested objects.



Is the above possible currently with PrimeNG, or do I need to create a custom DTO on the server returning only 'direct' fields for the PrimeNG table?










share|improve this question



























    0














    Good day



    Currently I am returning an array of objects looking like:



    {
    attendeeCount: 5
    bookDay: "2018-11-22T14:06:24.120Z"
    bookingComment: "This is a test"
    conferenceRoom: {id: 8, name: "Main Boardroom", seatingCount: 10, location: "Site Office", projector: "YES"}
    employee: {id: 111, title: "Mr.", initials: "J", preferredName: "John", lastName: "Smith", …}
    id: 1
    refreshment: {id: 1, name: "Coffee, Tea and Water"}
    timeSlot: "07:00 - 07:30"
    }


    The requirement then is that I should be able to render the PrimeNG data table using TypeScript like the below:



    public getRoomRosterTable() {
    this.conferenceRoomBookingService.getRoomRoster(this.dateValue, this.selectedConferenceRoom.id).subscribe(response => {
    console.warn(response);
    this.conferenceRoomBookings = response;
    }, error1 => {
    this.alertService.error(error1);
    });

    this.timeSlotCols = [
    {field: 'timeSlot', header: 'Time Slot'},
    {field: 'employee.preferredName' + 'employee.lastName', header: 'Slot Booked By'},
    {field: 'attendeeCount', header: 'Attendee Count'},
    {field: 'refreshment.name', header: 'Refreshment Details'},
    {field: 'bookingComment', header: 'Booking Comment'}
    ];
    }


    Combined with html looking like:



    <p-table [value]="conferenceRoomBookings" [reorderableColumns]="true" [columns]="timeSlotCols">
    <ng-template pTemplate="header" let-columns>
    <tr>
    <th *ngFor="let col of columns">
    <div style="text-align:center">
    {{col.header}}
    </div>
    </th>
    </tr>
    </ng-template>
    <ng-template pTemplate="body" let-rowData let-columns="columns">
    <tr>
    <td *ngFor="let col of columns">
    {{rowData[col.field]}}
    </td>
    </tr>
    </ng-template>
    </p-table>


    This however only renders the columns that have direct data bound. I cannot seem to get the table to pick up properties of nested objects.



    Is the above possible currently with PrimeNG, or do I need to create a custom DTO on the server returning only 'direct' fields for the PrimeNG table?










    share|improve this question

























      0












      0








      0







      Good day



      Currently I am returning an array of objects looking like:



      {
      attendeeCount: 5
      bookDay: "2018-11-22T14:06:24.120Z"
      bookingComment: "This is a test"
      conferenceRoom: {id: 8, name: "Main Boardroom", seatingCount: 10, location: "Site Office", projector: "YES"}
      employee: {id: 111, title: "Mr.", initials: "J", preferredName: "John", lastName: "Smith", …}
      id: 1
      refreshment: {id: 1, name: "Coffee, Tea and Water"}
      timeSlot: "07:00 - 07:30"
      }


      The requirement then is that I should be able to render the PrimeNG data table using TypeScript like the below:



      public getRoomRosterTable() {
      this.conferenceRoomBookingService.getRoomRoster(this.dateValue, this.selectedConferenceRoom.id).subscribe(response => {
      console.warn(response);
      this.conferenceRoomBookings = response;
      }, error1 => {
      this.alertService.error(error1);
      });

      this.timeSlotCols = [
      {field: 'timeSlot', header: 'Time Slot'},
      {field: 'employee.preferredName' + 'employee.lastName', header: 'Slot Booked By'},
      {field: 'attendeeCount', header: 'Attendee Count'},
      {field: 'refreshment.name', header: 'Refreshment Details'},
      {field: 'bookingComment', header: 'Booking Comment'}
      ];
      }


      Combined with html looking like:



      <p-table [value]="conferenceRoomBookings" [reorderableColumns]="true" [columns]="timeSlotCols">
      <ng-template pTemplate="header" let-columns>
      <tr>
      <th *ngFor="let col of columns">
      <div style="text-align:center">
      {{col.header}}
      </div>
      </th>
      </tr>
      </ng-template>
      <ng-template pTemplate="body" let-rowData let-columns="columns">
      <tr>
      <td *ngFor="let col of columns">
      {{rowData[col.field]}}
      </td>
      </tr>
      </ng-template>
      </p-table>


      This however only renders the columns that have direct data bound. I cannot seem to get the table to pick up properties of nested objects.



      Is the above possible currently with PrimeNG, or do I need to create a custom DTO on the server returning only 'direct' fields for the PrimeNG table?










      share|improve this question













      Good day



      Currently I am returning an array of objects looking like:



      {
      attendeeCount: 5
      bookDay: "2018-11-22T14:06:24.120Z"
      bookingComment: "This is a test"
      conferenceRoom: {id: 8, name: "Main Boardroom", seatingCount: 10, location: "Site Office", projector: "YES"}
      employee: {id: 111, title: "Mr.", initials: "J", preferredName: "John", lastName: "Smith", …}
      id: 1
      refreshment: {id: 1, name: "Coffee, Tea and Water"}
      timeSlot: "07:00 - 07:30"
      }


      The requirement then is that I should be able to render the PrimeNG data table using TypeScript like the below:



      public getRoomRosterTable() {
      this.conferenceRoomBookingService.getRoomRoster(this.dateValue, this.selectedConferenceRoom.id).subscribe(response => {
      console.warn(response);
      this.conferenceRoomBookings = response;
      }, error1 => {
      this.alertService.error(error1);
      });

      this.timeSlotCols = [
      {field: 'timeSlot', header: 'Time Slot'},
      {field: 'employee.preferredName' + 'employee.lastName', header: 'Slot Booked By'},
      {field: 'attendeeCount', header: 'Attendee Count'},
      {field: 'refreshment.name', header: 'Refreshment Details'},
      {field: 'bookingComment', header: 'Booking Comment'}
      ];
      }


      Combined with html looking like:



      <p-table [value]="conferenceRoomBookings" [reorderableColumns]="true" [columns]="timeSlotCols">
      <ng-template pTemplate="header" let-columns>
      <tr>
      <th *ngFor="let col of columns">
      <div style="text-align:center">
      {{col.header}}
      </div>
      </th>
      </tr>
      </ng-template>
      <ng-template pTemplate="body" let-rowData let-columns="columns">
      <tr>
      <td *ngFor="let col of columns">
      {{rowData[col.field]}}
      </td>
      </tr>
      </ng-template>
      </p-table>


      This however only renders the columns that have direct data bound. I cannot seem to get the table to pick up properties of nested objects.



      Is the above possible currently with PrimeNG, or do I need to create a custom DTO on the server returning only 'direct' fields for the PrimeNG table?







      javascript typescript datatable primeng primeng-datatable






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 14:19









      Letholdrus

      55431027




      55431027
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Could not get this to work with the PrimeNG table and resorted to using *ngFor combined with *ngIf wrapped in divs to detect nulls:



          <table class="table-bordered">
          <thead>
          <tr>
          <th>
          <div style="align-content: center">
          Time Slot
          </div>
          </th>
          <th>
          <div style="align-content: center">
          Booked By
          </div>
          </th>
          <th>
          <div style="align-content: center">
          Attendee Count
          </div>
          </th>
          <th>
          <div style="align-content: center">
          Refreshment Requirement
          </div>
          </th>
          <th>
          <div style="align-content: center">
          Booking Details
          </div>
          </th>
          </tr>
          </thead>
          <tbody>
          <tr *ngFor="let conferenceRoomBooking of conferenceRoomBookings">
          <td>
          <div *ngIf="conferenceRoomBooking.timeSlot">
          {{conferenceRoomBooking.timeSlot}}
          </div>
          </td>
          <td>
          <div *ngIf="conferenceRoomBooking.employee">
          {{conferenceRoomBooking.employee.preferredName}} {{conferenceRoomBooking.employee.lastName}}
          </div>
          </td>
          <td>
          <div *ngIf="conferenceRoomBooking.attendeeCount">
          {{conferenceRoomBooking.attendeeCount}}
          </div>
          </td>
          <td>
          <div *ngIf="conferenceRoomBooking.refreshment">
          {{conferenceRoomBooking.refreshment.name}}
          </div>
          </td>
          <td>
          <div *ngIf="conferenceRoomBooking.bookingComment">
          {{conferenceRoomBooking.bookingComment}}
          </div>
          </td>
          </tr>
          </tbody>
          </table>





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432951%2fbinding-and-using-an-objects-fields-within-an-object-returned-by-the-server-api%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Could not get this to work with the PrimeNG table and resorted to using *ngFor combined with *ngIf wrapped in divs to detect nulls:



            <table class="table-bordered">
            <thead>
            <tr>
            <th>
            <div style="align-content: center">
            Time Slot
            </div>
            </th>
            <th>
            <div style="align-content: center">
            Booked By
            </div>
            </th>
            <th>
            <div style="align-content: center">
            Attendee Count
            </div>
            </th>
            <th>
            <div style="align-content: center">
            Refreshment Requirement
            </div>
            </th>
            <th>
            <div style="align-content: center">
            Booking Details
            </div>
            </th>
            </tr>
            </thead>
            <tbody>
            <tr *ngFor="let conferenceRoomBooking of conferenceRoomBookings">
            <td>
            <div *ngIf="conferenceRoomBooking.timeSlot">
            {{conferenceRoomBooking.timeSlot}}
            </div>
            </td>
            <td>
            <div *ngIf="conferenceRoomBooking.employee">
            {{conferenceRoomBooking.employee.preferredName}} {{conferenceRoomBooking.employee.lastName}}
            </div>
            </td>
            <td>
            <div *ngIf="conferenceRoomBooking.attendeeCount">
            {{conferenceRoomBooking.attendeeCount}}
            </div>
            </td>
            <td>
            <div *ngIf="conferenceRoomBooking.refreshment">
            {{conferenceRoomBooking.refreshment.name}}
            </div>
            </td>
            <td>
            <div *ngIf="conferenceRoomBooking.bookingComment">
            {{conferenceRoomBooking.bookingComment}}
            </div>
            </td>
            </tr>
            </tbody>
            </table>





            share|improve this answer


























              0














              Could not get this to work with the PrimeNG table and resorted to using *ngFor combined with *ngIf wrapped in divs to detect nulls:



              <table class="table-bordered">
              <thead>
              <tr>
              <th>
              <div style="align-content: center">
              Time Slot
              </div>
              </th>
              <th>
              <div style="align-content: center">
              Booked By
              </div>
              </th>
              <th>
              <div style="align-content: center">
              Attendee Count
              </div>
              </th>
              <th>
              <div style="align-content: center">
              Refreshment Requirement
              </div>
              </th>
              <th>
              <div style="align-content: center">
              Booking Details
              </div>
              </th>
              </tr>
              </thead>
              <tbody>
              <tr *ngFor="let conferenceRoomBooking of conferenceRoomBookings">
              <td>
              <div *ngIf="conferenceRoomBooking.timeSlot">
              {{conferenceRoomBooking.timeSlot}}
              </div>
              </td>
              <td>
              <div *ngIf="conferenceRoomBooking.employee">
              {{conferenceRoomBooking.employee.preferredName}} {{conferenceRoomBooking.employee.lastName}}
              </div>
              </td>
              <td>
              <div *ngIf="conferenceRoomBooking.attendeeCount">
              {{conferenceRoomBooking.attendeeCount}}
              </div>
              </td>
              <td>
              <div *ngIf="conferenceRoomBooking.refreshment">
              {{conferenceRoomBooking.refreshment.name}}
              </div>
              </td>
              <td>
              <div *ngIf="conferenceRoomBooking.bookingComment">
              {{conferenceRoomBooking.bookingComment}}
              </div>
              </td>
              </tr>
              </tbody>
              </table>





              share|improve this answer
























                0












                0








                0






                Could not get this to work with the PrimeNG table and resorted to using *ngFor combined with *ngIf wrapped in divs to detect nulls:



                <table class="table-bordered">
                <thead>
                <tr>
                <th>
                <div style="align-content: center">
                Time Slot
                </div>
                </th>
                <th>
                <div style="align-content: center">
                Booked By
                </div>
                </th>
                <th>
                <div style="align-content: center">
                Attendee Count
                </div>
                </th>
                <th>
                <div style="align-content: center">
                Refreshment Requirement
                </div>
                </th>
                <th>
                <div style="align-content: center">
                Booking Details
                </div>
                </th>
                </tr>
                </thead>
                <tbody>
                <tr *ngFor="let conferenceRoomBooking of conferenceRoomBookings">
                <td>
                <div *ngIf="conferenceRoomBooking.timeSlot">
                {{conferenceRoomBooking.timeSlot}}
                </div>
                </td>
                <td>
                <div *ngIf="conferenceRoomBooking.employee">
                {{conferenceRoomBooking.employee.preferredName}} {{conferenceRoomBooking.employee.lastName}}
                </div>
                </td>
                <td>
                <div *ngIf="conferenceRoomBooking.attendeeCount">
                {{conferenceRoomBooking.attendeeCount}}
                </div>
                </td>
                <td>
                <div *ngIf="conferenceRoomBooking.refreshment">
                {{conferenceRoomBooking.refreshment.name}}
                </div>
                </td>
                <td>
                <div *ngIf="conferenceRoomBooking.bookingComment">
                {{conferenceRoomBooking.bookingComment}}
                </div>
                </td>
                </tr>
                </tbody>
                </table>





                share|improve this answer












                Could not get this to work with the PrimeNG table and resorted to using *ngFor combined with *ngIf wrapped in divs to detect nulls:



                <table class="table-bordered">
                <thead>
                <tr>
                <th>
                <div style="align-content: center">
                Time Slot
                </div>
                </th>
                <th>
                <div style="align-content: center">
                Booked By
                </div>
                </th>
                <th>
                <div style="align-content: center">
                Attendee Count
                </div>
                </th>
                <th>
                <div style="align-content: center">
                Refreshment Requirement
                </div>
                </th>
                <th>
                <div style="align-content: center">
                Booking Details
                </div>
                </th>
                </tr>
                </thead>
                <tbody>
                <tr *ngFor="let conferenceRoomBooking of conferenceRoomBookings">
                <td>
                <div *ngIf="conferenceRoomBooking.timeSlot">
                {{conferenceRoomBooking.timeSlot}}
                </div>
                </td>
                <td>
                <div *ngIf="conferenceRoomBooking.employee">
                {{conferenceRoomBooking.employee.preferredName}} {{conferenceRoomBooking.employee.lastName}}
                </div>
                </td>
                <td>
                <div *ngIf="conferenceRoomBooking.attendeeCount">
                {{conferenceRoomBooking.attendeeCount}}
                </div>
                </td>
                <td>
                <div *ngIf="conferenceRoomBooking.refreshment">
                {{conferenceRoomBooking.refreshment.name}}
                </div>
                </td>
                <td>
                <div *ngIf="conferenceRoomBooking.bookingComment">
                {{conferenceRoomBooking.bookingComment}}
                </div>
                </td>
                </tr>
                </tbody>
                </table>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 at 6:40









                Letholdrus

                55431027




                55431027






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432951%2fbinding-and-using-an-objects-fields-within-an-object-returned-by-the-server-api%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Berounka

                    Sphinx de Gizeh

                    Different font size/position of beamer's navigation symbols template's content depending on regular/plain...