数据表获取行ID并将其链接到每个单元格中

时间:2017-07-20 09:57:50

标签: datatables

我在获取行ID并将其放入每个单元格中的链接时遇到问题。 我从mysql db获取然后编码为json。

以下是从调试控制台获得的响应:

{"数据":[[" 10501"," BBBB AB(publ):8999"," 452075",&# 34; BBBB 20 BOX 17"," ASKERSUND"," ASKERSUN"," xDSL koppar"," Small",null,& #34; 10.50.1.0/24","详情< / A>&#34],

[" 10502"," BBBB AB(publ):8999"," 452026"," AAAA 11",&#34 ; LAX \ u00c5",#34; LAX \ u00c5"," xDSL koppar"," Small",null," 10.50.2.0/24&# 34;,"详情< / A>&#34],

[" 10503"," BBB AB(publ):8999"," 166201"," AAAAA 1 BOX 193",& #34; AVESTA"" AVESTAMT"" SWEFX2 / 4/8""小",NULL," 10.50.3.0/24& #34;"详情< / A>"] ...

Datable初始化代码:

var table = $('#example').DataTable({
                                      "aProcessing": true,
                                      "aServerSide": true,
                                      "ajax": "index.php?ajax",
                                          "columnDefs": [ {
                                           "targets": 11,
                                           "render": function ( data, type, meta ) {
                                                      return '<a target="_blank" href="add_device.php?rowid="'+data+'" class="btn btn-md btn-success">Add new device</a>';
                                           }
                                       }]
                            });

它生成链接但没有id,只需添加add_device.php?rowid =。

我尝试添加&#34;数据&#34;:数据,但控制台显示我&#34;数据未定义&#34;

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

О偶尔我发现了一个问题。刚刚将href链接更改为:

href="add_device.php?rowid=' + data[0] + '" class="btn btn-md btn-success">Add new device</a>';