简体   繁体   中英

Datatables Server Side - Using HTML

I use to datatables with server side option it is working but I pull some record from sql table and then I want to some column add html tags but it doesn't work I couldn't find a simple document. Can you help with this

Best Regards.

Js code is below

<script>
    $(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "server_side/server_processing.php",
        }
    } );
} );
</script>

Server-side code is below

$columns = array(
    array( 'db' => 'id', 'dt' => 0 ),
    array( 'db' => 'name',  'dt' => 1 ),
    array( 'db' => 'phone',   'dt' => 2 ),

);

i want it to be phone column in ajax file for example is below

<a href="tel:phone">phone</a>

thank you for your answer in advance

So here is my way to fix your problem, let me know if it works for you.

$(document).ready(function() {
    $('#example').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "server_side/server_processing.php"
        },
        columnDefs: [{
            targets: 2,
            render: function(data, type, row, meta) {
                if (type === 'display') {
                    data = '<a href="tel:' + data + '">' + data + '</a>';
                }

                return data;
            }
        }]
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM