I have an issue with trying to combining two columns into an ajax table

I have an issue with trying to combining two columns into an ajax table

forteforte Posts: 7Questions: 1Answers: 0
edited May 2018 in Free community support

What I would like is to merge the First_Name and Last_Name columns together. The code provided almost does it, but return is the first name and the second letter of the first name. I know it's because '+ data[1]+'...

I'm not sure how to call the Last_name object, I could use some help .

$(document).ready(function(){

var URL = 'here is were I put the URL to the server'

var table;
table = $('#example').DataTable( {
processing: false,
severSide: false,
ajax: {
url: URL,
type: "GET",
crossDomain: true,
dataType: "jsonp",
dataSrc: 'Seller_Leads_Information'
},

        columns : [
                {data: 'First_Name'},
                {data: 'Last_Name'},
                {data: 'Emailid'},
                {data: 'Phone'},
                {data: 'Street'},
                {data: 'City'}
            ],
            columnDefs: [{
                "targets": 0,
                "render": function ( data, type, row ) {
                        return data +'  '+ data[1]+' ' ;
                    },
                    "targets": 0
            },
             {"visible": false,  "targets": [ 1 ]}

             ]
} );

});

Replies

  • kthorngrenkthorngren Posts: 21,246Questions: 26Answers: 4,929

    Since you are using objects you will want something like this:
    return data +' '+ row.Last_Name +' ' ;

    And you can remove the Last_Name column from the table and columns.data if you like. You can still access it as part of the Datatables data.

    Kevin

  • forteforte Posts: 7Questions: 1Answers: 0

    that work thanks.....

  • forteforte Posts: 7Questions: 1Answers: 0
    edited May 2018

    One more question, could I use other render call inside the columnDefs: [ ] to return the address.

    var table;
    table = $('#example').DataTable( {
    processing: false,
    severSide: false,
    ajax: {
    url: URL,
    type: "GET",
    crossDomain: true,
    dataType: "jsonp",
    dataSrc: 'Seller_Leads_Information'
    },

            columns : [
                    {data: 'First_Name'},
                    {data: 'Last_Name'},
                    {data: 'Street'},
                    {data: 'City'},
                                        {data: 'State'},
                                        {data: 'Zip'},
                    {data: 'Phone'},
                    {data: 'Emailid'}
                ],
            columnDefs: [{
                    "targets": [ 0 ],
                    "render": function ( data, type, row ) {
                            return data +'  '+ row.Last_Name +' ' ;
                        }   
                },
                 {  "visible": false,  
                    "targets": [ 1 ]
                    },
    
                                "targets": [ 1],
                "render": function ( data, type, row ) {
                return data +'  '+ row.Street +' '+ row.City +' '+ row.State+' '+ row.Zip+' ' ;
                        }   
                },
                 {  "visible": false,  
                    "targets": [ 2 ],[ 3 ],[ 4 ]
                    }
    

    ]

  • kthorngrenkthorngren Posts: 21,246Questions: 26Answers: 4,929

    What you have should work. But it looks like you are hiding that column with this:

         {  "visible": false, 
            "targets": [ 1 ]
            },
     
    

    Is it not working for you?

    Kevin

  • forteforte Posts: 7Questions: 1Answers: 0

    Sorry, I should have giving you the full code ... I'm getting a syntax error, could you take an other look for me ... thx

    var table;
    table = $('#example').DataTable( {
    processing: false,
    severSide: false,
    ajax: {
    url: URL,
    type: "GET",
    crossDomain: true,
    dataType: "jsonp",
    dataSrc: 'Seller_Leads_Information'
    },

            columns : [
                    {data: 'First_Name'},
                    {data: 'Last_Name'},
                    {data: 'Street'},
                    {data: 'City'},
                    {data: 'State'},
                    {data: 'Zip'},
                    {data: 'Phone'},
                    {data: 'Emailid'}
                ],
            columnDefs: [{
                    "targets": [ 0 ],
                    "render": function ( data, type, row ) {
                            return data +'  '+ row.Last_Name +' ' ;
                        }   
                },
                 {  "visible": false,  
                    "targets": [ 1 ]
                    },
    
                     "targets": [ 2 ], <!--Here were I'm getting a syntax error -->
                    "render": function ( data, type, row ) {
                return data +'  '+ row.Street +' '+ row.City +' '+ row.State+' '+ row.Zip+' ' ;
            }  
    },
     {  "visible": false, 
        "targets": [ 3 ],[ 4 ],[ 5 ]
        }
                 ]
    
    } );
    
  • forteforte Posts: 7Questions: 1Answers: 0
    edited May 2018

    I work it out.... thx for all the help...

    var URL = 'here is were I put the URL to the server'
    var table;
    table = $('#example').DataTable( {
    processing: false,
    severSide: false,
    ajax: {
    url: URL,
    type: "GET",
    crossDomain: true,
    dataType: "jsonp",
    dataSrc: 'Seller_Leads_Information'
    },

            columns : [
                {data: 'First_Name'},
                {data: 'Last_Name'},
                {data: 'Street'},
                {data: 'City'},
                {data: 'State'},
                {data: 'Zip'},
                {data: 'Phone'},
                {data: 'Emailid'}
            ],
            columnDefs: [{
                    "targets": [ 0 ],
                    "render": function ( data, type, row ) {
                            return data +'  '+ row.Last_Name +' ' ;
                        }
                        },
                        {
                        "targets": [ 2 ],
                        "render": function ( data, type, row ) {
            return  row.Street +' '+ row.City +' '+ row.State+' '+ row.Zip+' ' ;
        }   
                        },
                        {"visible": false,  
                        "targets": [ 1, 3, 4, 5]
                        }] 
    });
    
This discussion has been closed.