DataTables列中所有行的超链接

use*_*427 7 javascript jquery datatables

我正在使用DataTables生成一个表.有一个包含订单号的列.

例如: ...

我需要每一行此列中有一个超链接到view/order?id=?哪里?是行的内容订单号列.例如,第一行将是一个超链接view/order?id=1321755等.

我能做到的最简单的方法是什么?

在此输入图像描述

这是我用来初始化DataTables的代码:

<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        $('#example').dataTable( {
            "serverSide": true,
            "ajax": {
                    "url": "../server_processing/orders.php",
                    "type": "POST"
                    },
            "order": [[ 0, "desc" ]]
        } );
    } );
</script>

  <table id="example" class="display" cellspacing="0" width="100%">
    <thead>
      <tr>
        <th>Order No</th>
        ...
      </tr>
    </thead>
    <tbody>
    </tbody>
  </table>
Run Code Online (Sandbox Code Playgroud)

Moo*_*ozz 14

看看这个:http: //datatables.net/reference/option/columns.render

指定列定义时,可以添加列呈现回调.

var columnsDef = [
...
{
    "title": "Order No.",
    "render": function (data, type, row, meta) {
        return '<a href="view/order?' + data + '">' + data + '</a>';
    }
},
...
];

$("#table").dataTable({
    ...
    "columns": columnsDef,
    ...
});
Run Code Online (Sandbox Code Playgroud)

该列中的数据将更改为渲染函数返回的内容.