columns.render multiple object properties from one-to-many join

columns.render multiple object properties from one-to-many join

tam.hassan7tam.hassan7 Posts: 2Questions: 1Answers: 0

Re: https://editor.datatables.net/manual/php/array-joins#Client-side

{ data: "access", render: "[, ].name" }

This renders only the name property of each object in the array.
How to simply render multiple properties of each object in the array?

Example: I want to render:
name, description, comment
for each object, and separate the array objects with two break tags.

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You would need to use a function for columns.render and loop over the data array, building the string you want.

    For example:

    data: "access",
    render: function ( data, type, full ) {
      return $.map( data, function ( d, i ) {
        return d.name +' '+ d.description;
      } ).join( ', ' );
    }
    

    Allan

  • tam.hassan7tam.hassan7 Posts: 2Questions: 1Answers: 0
    edited June 2015

    Edited:

    Brilliant.. It works like a charm. Thank you!

This discussion has been closed.