如何将列数据作为dataTable(JQUERY)中另一列数据的超链接

时间:2016-09-19 16:27:27

标签: jquery datatable

我正在尝试为来自其他列数据的数据表中的特定列创建超链接 enter image description here

例如,位置列应该具有来自位置列

的数据的超链接

我试过,它只有位置栏的超链接

columnDefs: [             
{
                  targets:1,

                        render: function (dataSet, type, row, meta) {

                            if (type === 'display') {
                                dataSet = '<a href="http://localhost/application/org?officeid=' + encodeURIComponent(dataSet) + '">' + dataSet + '</a>';
                            }

                            return dataSet;
                        }
                    }
                ]

1 个答案:

答案 0 :(得分:1)

您需要访问row属性。 row表示整行数据,因此您可以通过索引引用它:

if (type === 'display') {
      dataSet = '<a href="http://localhost/application/org?officeid=' + row[1] + '">' + dataSet + '</a>';
   }

这假设第1列中的数据是我不确定您的数据中存在的Office ID,您可能必须修改您的查询以确保返回此信息。