角度数据表 - 呈现以组合来自多列的数据

时间:2015-10-01 16:07:58

标签: angularjs angular-datatables

我的angularjs数据表控制器代码如下。使用DTColumnBuilder选项,如何提供列渲染器以显示格式化数据

$scope.dtOptions = DTOptionsBuilder.fromSource(CompanyService.loadUrl()).withPaginationType('full_numbers').withOption('rowCallback', rowCallback);
$scope.dtColumns = [
    DTColumnBuilder.newColumn('id').withTitle('Id'),
    DTColumnBuilder.newColumn('name').withTitle('Name'),
    DTColumnBuilder.newColumn('description').withTitle('Description'),
    DTColumnBuilder.newColumn('active_status').withTitle('Status')
];

1 个答案:

答案 0 :(得分:5)

帮助我编写渲染器https://github.com/l-lin/angular-datatables/issues/224

的链接
    $scope.dtColumns = [
    DTColumnBuilder.newColumn('id').withTitle('Id'),
    DTColumnBuilder.newColumn('name').withTitle('Name'),

    DTColumnBuilder.newColumn(null).withTitle('Address').renderWith(function(data,type,full) {
        var address =  '<address>' + data.address_line_1+ '<br>';
        if (data.address_line_2.trim())  {
            address = address + data.address_line_2+ '<br>';
        }       
        address = address + data.location + '<br>'
                 + data.city + '-' + data.pincode + '<br>'
                 + data.state +'<br>' 
                 + data.country;
        return address;         

    }),

    DTColumnBuilder.newColumn('city').withTitle('City'),
    DTColumnBuilder.newColumn('state').withTitle('State'),
    DTColumnBuilder.newColumn('country').withTitle('Country'),
];