简体   繁体   English

如何在jQuery数据表中调用函数

[英]How to call Function in Jquery Datatable

I have these lines of code. 我有这些代码行。 I want to add function to some row. 我想向某些行添加功能。 When clicked it runs another function. 单击后,它将运行另一个功能。 But It not recognise function declaration.How can I call function when clicked some row? 但是它不能识别函数声明。单击某行时如何调用函数? and how can i send parameters to that function associated with that row. 以及如何将参数发送到与该行关联的函数。

$(document).ready(function() {
      var restVul = function() {
        alert("tik");
      }

      $.ajax({
        url: "https://localhost:450/rest/products?pageNumber=1&pageCount=80",
        type: "POST",
        dataType: "json",
        headers: {
          'Content-Type': 'application/json'
        },
        traditional: true,
        contentType: "application/json; charset=utf-8",
        processData: false,
        data: JSON.stringify(hostAddresses),
        success: function(response) {
          console.log(response);
          for (var i = 0; i < response.length; i++) {
            var trHTML = '';
            for (var j = 0; j < response[i].Products.length; j++) {
              trHTML += '<tr class="clickable-row" data-href="index.html"><td>' + response[i].IP + '</td><td onclick="function () {alert();  }">' + response[i].Products[j].Product + '</td><td>' + response[i].Products[j].CVECount + '</td></tr>';
            }
            $('#ProductsTableBody').append(trHTML);
          }

          $('.js-exportable').DataTable({
            dom: 'Bfrtip',
            responsive: true,
            buttons: [
              'copy', 'csv', 'excel', 'pdf', 'print'
            ]
          });
        },
        error: function(xhr) {
          console.log("Hata Oluştu...");
        }
      })

Use following code in the row 在行中使用以下代码

columns: [
{"data": "xxx", "width": "10%","visible": false, "render": function (data, type, row, meta) {   }    },
]

Use following code inside the function to make a clickable link on column 在函数内使用以下代码在列上创建可点击的链接

if (type === 'display') {
        return $('<a>')
        .attr('href', ' ')
        .text(data)
        .wrap('<div></div>')
        .parent()
        .html();
     } else {
          return data;
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM