添加标记html <a> on datatable Ajax sourced data

时间:2017-07-11 09:08:45

标签: html ajax datatable datatables

I use add tag link in basic sourced data which it work.

<td><a href="review/data.html?id=<?php echo $_POST['id'] ?>">Action</a></td>

But i not work to Ajax sourced data in add tag html

 $(document).ready(function() {
    $('#example').DataTable( {
        "ajax": "api/all",
        "columns": [
            { "data": "du_id" },
            { "data": "site_id" },
            { "data": "status" },
            { "data": "submission_end_time" },
            { "data": "region" },
            { "data": '<a href="'+"id"+'"></a>' }
        ]
    } );
} );

2 个答案:

答案 0 :(得分:0)

有几种方法可以做到这一点,一种方法是使用defaultContent,或者你可以使用render,这样可以提供更多的灵活性:

{ "data": "submission_end_time" },
{ "data": "region" },
{
    'render': function (data, type, full, meta) {
        return '<a href="'+ data +'"></a>';
        }
}

答案 1 :(得分:0)

   $(document).ready(function() {
    $('#example').DataTable( {
        "ajax": "{{url('api/all')}}",
        "columns": [
            { "data": "du_id" },
            { "data": "site_id" },
            { "data": "status" },
            { "data": "submission_end_time" },
            { "data": "region" },
            { "data": "id"  ,  "render": function ( data, type, full, meta ) {
      return '<a href="'+data+'">Action</a>';
    }}
        ]
    } );
} );