[英]Clicking on a row must redirect the page to another URL
I'm using a Datatable in my .Net MVC application. 我在.Net MVC应用程序中使用了数据表。 Currently I have implemented the following: 目前,我已经实现了以下内容:
Atop of this I have one condition applied which is as follows: 在此之上,我应用了一个条件,如下所示:
Here's my current script: 这是我当前的脚本:
"ajax":
{
"url": "/Request/Search/LoadData",
"type": "POST",
"datatype": "json",
"data": function (d) {
d.obj = searchFilters();
},
},
"columns":
[
{
"data": "RequestNo",
"render": function (data, type,row, full, meta) {
if (row.Status == "Draft") {
return '<a href="/ChopRequest/Request?RequestId=' + data + '">' + data + '</a>';
} else {
return '<a href="/ChopRequest/ViewRequest/Index?id=' + data + '">' + data + '</a>';
}
}
}
]
So in this case the only option the user has is to click the data in the very first column. 因此,在这种情况下,用户唯一的选择是单击第一列中的数据。 Instead I want the entire row to be clickable while preserving the above mentioned conditions. 相反,我希望整个行在保留上述条件的情况下都可单击。
Can anyone tell me how can I achieve this? 谁能告诉我如何做到这一点?
You can detect clicks in other cells and redirect browser to the link located in the first column of the same row. 您可以检测其他单元格中的点击,然后将浏览器重定向到同一行第一列中的链接。
For example: 例如:
$('#example').on('click', 'tbody td', function(){
window.location = $(this).closest('tr').find('td:eq(0) a').attr('href');
});
$(document).ready(function (){ var table = $('#example').DataTable(); $('#example').on('click', 'tbody td', function(){ window.location = $(this).closest('tr').find('td:eq(0) a').attr('href'); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://cdn.datatables.net/r/dt/dt-1.10.9/datatables.min.js"></script> <link href="https://cdn.datatables.net/r/dt/dt-1.10.9/datatables.min.css" rel="stylesheet"/> <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </thead> <tfoot> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </tfoot> <tbody> <tr> <td><a href="//www.datatables.net">Tiger Nixon</a></td> <td>System Architect</td> <td>Edinburgh</td> <td>61</td> <td>2011/04/25</td> <td>$320,800</td> </tr> </tbody> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.