我正在使用angular datatable创建表格,以下是我工作的plnkr - http://plnkr.co/edit/pQ0TrNEjzyXmvFcIvkSr?p=preview
这里我想将两个列数据合并为一个,即显示地址1&地址2作为地址类似 - addr1 - addr2和(2)在表列而不是链接中显示图像。
我试过了 -
DTColumnBuilder.newColumn('addr1' - 'addr2').withTitle('Address 1'),
和DTColumnBuilder.newColumn('addr1 - addr2')
但没有运气(抛出错误)
请帮我解决这个问题。感谢。
我的剧本 -
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);
答案 0 :(得分:4)
您必须在列angular-datatable documentation
上使用renderWith$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;
}
更新的plunker:http://plnkr.co/edit/T2XMUFxORSy3z7dDgRcc?p=preview
如果需要,可以添加图片...