Joining values of two columns in one

Joining values of two columns in one

jigar311982jigar311982 Posts: 70Questions: 31Answers: 0

Hello,

I have server-side data and rendering,

HTML I am joining customer_firstname and customer_lastname in the Customer row.

                <tr>
                    <th></th>
                    <th>Customer</th>
                    <th>Just Nothing</th>
                    <th>Invoice Number</th>
                    <th>Amount</th>
                    <th>Date</th>                                   
                    <th>Payment Due</th>
                </tr>

            columns: [
                {data: 'invoice_id'},
                {data: 'customer_firstname'},
                {data: 'customer_lastname'},
                {data: 'invoice_number'},
                {data: 'invoice_amount'},
                {data: 'invoice_date'},
                {data: 'payment_due_date'},
            ],

            columnDefs: [
                {
                    targets: 1,
                    render: function ( data, type, row ) {
                        return data +' ('+ row[2]+')';
                    },

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

            ],

The output of the above code results in Firstname (Undefined), I don't know why the value of customer_lastname is not rendering correctly?

If I display customer_lastname in a separate column, it shows correctly.

What wrong I did in this

Thanks,

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    I'm guess it should be

            render: function ( data, type, row ) {
                return data +' ('+ row.customer_lastname +')';
            },
    

    as you're using objects.

    Colin

This discussion has been closed.