访问Datatables中另一列中的数据

And*_*yen 4 javascript jquery datatables

我正在使用Datatables,我正在尝试访问另一列中的数据.我不清楚我是否应该使用columns.data或者是否应该通过使用获取列索引来采用另一种方法?

目的

  • 在第二个渲染函数中,我希望第一个makeSlug(data)引用"data": "district"第一个和第二个渲染函数保持相同和引用"data": "school"

scripts.js中

"columns": [
{ "data": "district",
    "render": function (data, type, row, meta) {
        return '<a href="/schools/' + makeSlug(data) + '">' + data + '</a>';
    }
},
{ "data": "school",
    "render": function (data, type, row, meta) {
        return '<a href="/schools/' + makeSlug(data) + '/' + makeSlug(data) + '">' + data + '</a>';
    }
},
{ "data": "subject"},
{ "data": "rate"},
{ "data": "test_takers"}
],
Run Code Online (Sandbox Code Playgroud)

Gyr*_*com 10

第三个参数row是包含该行的完整数据集的数组.使用row['district']访问district属性.

例如:

{ 
   "data": "school",
   "render": function (data, type, row, meta) {
        return '<a href="/schools/' + makeSlug(row['district']) + '/' + makeSlug(data) + '">' + data + '</a>';
    }
}
Run Code Online (Sandbox Code Playgroud)