具有多个超链接的CSV到HTML表



想知道有人可以为我提供帮助。

我正在使用此示例CSV到HTML表

我正在尝试将额外的列格式化为超链接,但老实说,没有JS技能将非常感谢任何帮助。下面的示例显示了一列的代码。

 <script>
  //my custom function that creates a hyperlink
  function format_link(link){
    if (link)
      return "<a href='" + link + "' target='_blank'>" + link + "</a>";
    else
      return "";
  }
  //initializing the table
  CsvToHtmlTable.init({
    csv_path: 'data/Health Clinics in Chicago.csv', 
    element: 'table-container', 
    allow_download: true,
    csv_options: {separator: ',', delimiter: '"'},
    datatables_options: {"paging": false},
    custom_formatting: [[4, format_link]] //execute the function on the 4th column of every row
  });
</script>

csv-to-html-table的文档指出:

如果要为一个或多个列进行自定义格式,则可以 传递包含列的索引和A的数组数组 定制功能用于格式化它。您可以传递多个格式化器 它们将按顺序执行。

在下面的示例中,我演示了多个链接的数组数组。在我的示例第4列和第6列具有链接。

<script>
  //my custom function that creates a hyperlink
  function format_link(link){
    if (link)
      return "<a href='" + link + "' target='_blank'>" + link + "</a>";
    else
      return "";
  }
  //initializing the table
  CsvToHtmlTable.init({
    csv_path: 'data/Health Clinics in Chicago.csv', 
    element: 'table-container', 
    allow_download: true,
    csv_options: {separator: ',', delimiter: '"'},
    datatables_options: {"paging": false},
    custom_formatting: [[4, format_link], [6, format_link]] //execute the function on the 4th column of every row
  });
</script>

最新更新