简体   繁体   English

数据表服务器端-使用HTML

[英]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. 我使用带有服务器端选项的数据表可以正常工作,但是我从sql表中提取了一些记录,然后我想在某些列中添加html标记,但是它不起作用,我找不到简单的文档。 Can you help with this 你能帮忙吗

Best Regards. 最好的祝福。

Js code is below js代码如下

<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 我希望它成为ajax文件中的电话专栏,例如下面

<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;
            }
        }]
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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