question about Child rows field visualization

question about Child rows field visualization

GargiucnGargiucn Posts: 104Questions: 29Answers: 0

I'm working with the example:
https://datatables.net/examples/api/row_details.html.
I should display an array field that comes from a mjoin relationship:

{
  data: "tags",
  render: "[, ].tag_descr"
},  

I would like to know how to display the tags field correctly in the function:

/* Formatting function for row details - modify as you need */
function format ( d ) {
    // `d` is the original data object for the row
    return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
        '<tr>'+
            '<td>List of tags:</td>'+
            '<td>'+d.<<<tags>>>+'</td>'+
        '</tr>'+
    '</table>';
}

to get the same view I get with render.

Thanks for your help,
Giuseppe

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765
    edited October 2018

    Maybe the Javascript join() method would work.

    Kevin

  • GargiucnGargiucn Posts: 104Questions: 29Answers: 0

    I tried with:

                {
                    data: "tags", 
                    //render: "[, ].tag_descr"
                    render: function ( d, type, row ) {
                        htmltags = "";
                        htmltags = d.join();
                        return htmltags;
                    }
                },  
    

    inserendolo nella funzione:

    /* Formatting function for row details - modify as you need */
    function format ( d ) {
        // `d` is the original data object for the row
        return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
            '<tr>'+
                '<td>Tags:</td>'+
                '<td>'+htmltags+'</td>'+
            '</tr>'+
            '<tr>'+
                '<td>Notes:</td>'+
                '<td>'+d.bandi.ban_note+'</td>'+
            '</tr>'+
            '<tr>'+
                '<td>Files:</td>'+
                '<td>'+html+'</td>'+
            '</tr>'+
        '</table>';
    }
    

    I tried to get a result similar to what I used to view pdf files attached and this works great:

                {data: "files_bandi",
                    render: function ( d, type, row ) {
                        if( d.length>0) {
                            html = "";
                            for ( i = 0; i < d.length; i++ ){
                                //html+= row.files[i].file_id+"&nbsp;";
                                //html+= row.files[i].file_web+"&nbsp;";
                                
                                //<a href="#" data-toggle="tooltip" title="Some tooltip text!">Hover over me</a>
                                
                                html+= '<a style="display: inline-block; margin-right: 5px;" href="'
                                    +table.file( 'files_bandi', row.files_bandi[i].file_id ).file_web
                                    +'" target="_blank" data-toggle="tooltip" title="'
                                    +table.file( 'files_bandi', row.files_bandi[i].file_id ).file_nome
                                    +'"><i class="fa fa-file-pdf-o fa-lg"></i></a>';
                            }
                        }
                        else
                        {
                            html = 'No files.';
                        }
                        return html;
                    }
                },
    

    but I always get the same result...
    [object Object],[object Object],[object Object]

    Giuseppe

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin
    Answer ✓
    var a = [];
    for ( var i=0, ien=d.tags.length ; i<ien ; i++ ) {
      a.push( d.tags[i].tag_descr );
    }
    var str = a.join(', ');
    

    will give you the comma / space separated string.

    Allan

  • GargiucnGargiucn Posts: 104Questions: 29Answers: 0

    OK! modified just a little for my function works perfectly!

                {
                    data: "tags", 
                    //render: "[, ].tag_descr"
                    render: function ( d, type, row ) {
                        htmltags = "";
                        var a = [];
                        for ( var i=0, ien=d.length ; i<ien ; i++ ) {
                            a.push( d[i].tag_descr );
                        }
                        htmltags = a.join(', ');
                        return htmltags;
                    }
                },  
    

    Thanks for your help,
    Giuseppe

This discussion has been closed.