【问题标题】:jquery datatable - How to use render function get data from another columnjquery datatable - 如何使用渲染函数从另一列获取数据
【发布时间】:2026-02-08 20:40:01
【问题描述】:

我在每一行都有添加按钮,但我想检查信息列数据是否为 ​​N/A,然后没有显示按钮,我尝试在我的代码中设置如下渲染,但它不起作用

{
    "targets": -1,
    "data": null,
    "render": function ( data, type, row ) 
    {
        if (row.info != 'N/A') {
        return "<button href='" + row.index() + "' class='btn btn-info'>View</button>"
        } else { return "" }
     }
    }                    
}

非常感谢任何帮助/建议。 如果有帮助,愿意发布更多信息。

【问题讨论】:

  • "render": function (data, type, row) { if (row.info!='N/A') return "" }

标签: php jquery datatables


【解决方案1】:

此处记录了渲染:https://datatables.net/reference/option/columns.render

您没有使用此处记录的相同名称的参数,但在示例中,您将使用 full 访问所有可用列,data 是当前列。我不确定你从哪里得到field。因此来自info 的数据将通过full.info 访问。

一个例子是:

"render": function ( data, type, full, meta ) {
  return '<a href="'+data+'">' + full.info + '</a>';
}

【讨论】:

    【解决方案2】:

    工作Link Here

    "render": function(data, type, full, meta ) {
        if (full.info != 'N/A') {
            return "<button href='" + row.index() + "' class='btn btn-info'>View</button>"
        } else {
            return ""
        }
    }
    

    【讨论】: