【问题标题】:Add link to Ajax sourced data in jQuery Datatables在 jQuery Datatables 中添加指向 Ajax 源数据的链接
【发布时间】:2019-09-07 02:32:49
【问题描述】:

我想将链接/href 添加到第二列(其中包含“C”数据的那一列)。我试过列渲染功能,但它只有当前列的数据。

https://datatables.net/reference/option/columns.render

我想将不同列的数据用于第 2 列的锚标记

这家伙在这里

https://stackoverflow.com/a/47696609/11575565

解释了使用 rowID 可以解决我的问题,但这不起作用。

我尝试在 ajax 函数上使用 $.getJSON 和 append(),但效果不佳。

    $(document).ready(function() {
  var table = $('#bla').DataTable({
    "ajax" : "blist.json",
    "columns" : [
        { "data" : null,defaultContent: "-" },
        { "data" : "C" },
        { "data" : "B" },
        { "data" : "D" },
        { "data" : null,defaultContent: "-" },
        { "data" : null,defaultContent: "-" },
    ],

[blist.json中的数组有数据"A","B","C","D","E"]

【问题讨论】:

  • render( data, type, row, meta ) ...row 保存所有列值...
  • 谢谢大卫。文档中并不清楚

标签: javascript jquery ajax datatables


【解决方案1】:

假设您的 Link 值在键 E 中,那么您将能够使用如下所示的渲染。

"columns" : [
  { "data" : null,defaultContent: "-" },
  { "data" : "C", 
    "render": function(data, type, row, meta){
      if(type === 'display'){
          data = '<a href="' + row.E + '">' + data + '</a>';
      }
      return data;
    }
  },
  { "data" : "B" },
  { "data" : "D" },
  { "data" : null,defaultContent: "-" },
  { "data" : null,defaultContent: "-" },
]

【讨论】:

    猜你喜欢
    • 2014-10-09
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 2013-05-15
    • 2015-01-17
    相关资源
    最近更新 更多