1

I have a datatable that I want to show the information from my SharePoint List. The table has three headers: Name, Department and Address. The Address column should combine two SharePoint columns(Address Line 1 and Address Line 2) from the same list and display in that column.

How do I combine the two columns into one datatable column? The Address Line 2 should also start on the next line after Address Line 1.

This is my current code for the datatable.

function mySuccHandler(data) {
           
        console.log(data);
        
        $('#registration_table').DataTable({
                "pageLength": 20,
                "aaSorting": [],
                "aLengthMenu": [[20, 50, 75, -1], [20, 50, 75, "All"]],
                "iDisplayLength": 20,
                "pagingType": "full_numbers",
                "aaData": data.d.results,               
                "columnDefs": [
                   {
                       "targets": '_all',
                       "className": 'dt-left'
                   }
                ],
                "order": [[4,"asc"]],
                "aoColumns": [               
                
                {
                    "mData": "FullName"
                },
                {
                    "mData": "Dept"
                },

                {
                    "mData": "AddressLine1"
                                     
                },
                {
                    "mData": "AddressLine2"                                    
                }

                ]
                
            }); 
    }

1 Answer 1

0

You can change the aoColumns as given below:

"aoColumns": [                          
    {
        "mData": "FullName"
    },
    {
        "mData": "Dept"
    },
    {
        "mData": getFullAddress                  
    }
]

Where getFullAddress is a function like:

function getFullAddress(data, type, dataToSet) {
    return data.AddressLine1 + "<br>" + data.AddressLine2;
}

You can also try other ways given in below reference thread.

Reference: How to put multiple data in a datatable column?

1
  • Thank you. It works, I also hid the extra column with bVisible.
    – soh
    Apr 22 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.