Datatables.js超链接单元

时间:2018-07-20 10:52:19

标签: javascript jquery datatables

使用DataTables.js,并且需要在列中的每个单元格中都有一个可点击的网址。目前,我正尝试将其转到google.com。

我正在努力使其正常运行,并且在准备好几本教程之前,我的代码如下;

jQuery(window).load(function () {
jQuery.ajax({
    url: "Requisitions.aspx/GetMyRequisitions",
    method: "POST",
    data: '{"ReqId":"' + reqId + '", "Title": "' + reqTitle + '", "PrimaryHiringManager": "' + reqHiringManager + '", "StartDate": "' + reqStartDate + '", "Status": "' + reqStatus + '", "Applicants": "' + reqApplicants + '"}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
        jQuery('#MyRequisitions').DataTable({
            data: data.d,
            retrieve: true,
            order: [[5, "desc"]],
            responsive: true,

            column:
                [
                    { "data": "ReqId" },
                    {
                        "data": "Title",
                        "render": function (data, type, row, meta) {
                                data = '<a href="https://www.google.com/"></a>';
                            return data;
                        }
                    },
                    { "data": "PrimaryHiringManager" },
                    { "data": "StartDate" },
                    { "data": "Status" },
                    { "data": "Applicants" }
                ]
        });
    }
});

});

2 个答案:

答案 0 :(得分:0)

亲爱的

{"data": "Title",
                     "render": function(data, type, full, meta) {
                        return '<a href="#" onclick="selectCompany([' + data + '])">' + data + '</a>';
                        }
                     },

答案 1 :(得分:0)

  

具有超链接的超链接

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

点击超链接调用功能

{  
data: null, render: function (data, type, row) {  
return "<a href='#' class='btn btn-danger' onclick=DeleteData('" + row.CustomerID + "'); >Delete</a>";  
}  
},

function DeleteData(CustomerID) {  
        if (confirm("Are you sure you want to delete ...?")) {  

        }  
        else {  
            return false;  
        }  
    } 
  

输出

Output

  

文章链接,如果您需要更多详细信息

Link to Datatables Grid Example