0

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

1

1 Answer 1

2

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;
            }
        }]
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.