0

I am using angular datatable to create tables and following is my working plnkr - http://plnkr.co/edit/pQ0TrNEjzyXmvFcIvkSr?p=preview

Here I want to merge two column data to one, i.e. to show Address 1 & Address 2 as Address something like - addr1 - addr2 and also (2) to show image in table column instead of link.

I tried -

DTColumnBuilder.newColumn('addr1' - 'addr2').withTitle('Address 1'), and DTColumnBuilder.newColumn('addr1 - addr2') but no luck(throwing error)

Please help me with this. Thanks.

My Script -

var dd = [];
dd = [
 {"Img": "http://img.banggood.com/thumb/other_items/upload/2012/liangping/animal%20head%20masks-011%20(4).jpg", "Name": "Tiger Nixon", "Age": "61", "addr1": "234 My addr 1", "addr2": "234 My addr 2"},
 {"Img": "http://a.deviantart.net/avatars/a/n/animal-animes.png", "Name": "Garrett Winters","Age": "63", "addr1": "235 My addr 1", "addr2": "235 My addr 2"}
 ]; 
 $scope.dtColumns = [
 DTColumnBuilder.newColumn('addr1').withTitle('Address 1'),
 DTColumnBuilder.newColumn('addr2').withTitle('Address 2'),
 DTColumnBuilder.newColumn('Img').withTitle('Image'),
 DTColumnBuilder.newColumn('Name').withTitle('Name'),
 DTColumnBuilder.newColumn('Age').withTitle('Age')
 ];
 $scope.dtOptions = DTOptionsBuilder.newOptions()
 .withOption('data', dd); 
asked Oct 10, 2015 at 12:00

1 Answer 1

4

You have to use renderWith on your column angular-datatable documentation

$scope.dtColumns = [
 DTColumnBuilder.newColumn('addr1').withTitle('Address 1'),
 DTColumnBuilder.newColumn('addr2').withTitle('Address 2'),
 DTColumnBuilder.newColumn(null).withTitle('Full Address').renderWith(addressHtml),
 DTColumnBuilder.newColumn('Img').withTitle('Image'),
 DTColumnBuilder.newColumn('Name').withTitle('Name'),
 DTColumnBuilder.newColumn('Age').withTitle('Age')
];
$scope.dtOptions = DTOptionsBuilder.newOptions()
 .withOption('data', dd);
function addressHtml(data, type, full, meta) {
 return data.addr1 + ' - ' + data.addr2;
}

the updated plunker : http://plnkr.co/edit/T2XMUFxORSy3z7dDgRcc?p=preview

You can add image if you need ...

answered Oct 10, 2015 at 12:28
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.