Jquery Datatables 如何在渲染函数中获取列 Id
Jquery Datatables How to get column Id in render function
我正在尝试创建对行单元格的引用。这是我的代码:
<table class="table table-striped table-bordered table-hover little_margin_table" id="data-table" width="100%">
<thead>
<th>First Name</th>
<th>Email</th>
<th>Password</th>
</thead>
<tbody>
@foreach (var item in Model.Items)
{
<tr id="@item.Id">
<td>@item.FirstName</td>
<td>@item.Email</td>
<td>@item.Password</td>
</tr>
}
</tbody>
</table>
Javascript代码:
$(document).ready(function () {
$('#data-table').dataTable({
bFilter: false,
aoColumnDefs: [
{
bSortable: false,
aTargets: [1, 2],
},
{
"targets": 0,
"render": function (data, type, full, meta) {
return '<a href = "@(Url.Action("IndexPage", "Company"))/' + ROWID '</a>';
}
},
]
})
在这里,我假设行 Id:
<tr id="@item.Id">
如何让它进入函数渲染:
"render": function (data, type, full, meta) {
return '<a href = "@(Url.Action("IndexPage", "Company"))/' + ROWID '</a>';
请帮忙。
您可以在表格中添加额外的列:
<td>@item.FirstName</td>
<td>@item.Email</td>
<td>@item.Password</td>
<td>@item.Id</td>
在数据表中设置为隐藏 init 代码:
'bVisible': false
当您使用 render
时,您现在可以从 full
中获取 Id 值:
"render": function (data, type, full, meta) {
return '<a href = "@(Url.Action("IndexPage", "Company"))/' + full[3] + '</a>';
您可以使用委托的事件处理程序在单击链接时将id
添加到链接中:
$("#data-table").on("click", "td:eq(0) a", function(e) {
this.href+=$(this).closest('tr').attr('id');
})
并且忘记在render
回调中向href
添加ROWID
。该表是服务器端生成的,您的Model.items
永远不会作为数据传递给客户端,因此我看不到任何其他解决方法。
相关文章:
- 使用jQuery来foreach iframe-src,并通过函数获取ID和操作
- Javascript函数获取元素内容
- 从Javascript函数获取字符串
- Jasmine测试工厂函数调用本地函数和另一个函数-获取错误:应该是间谍,但得到了function
- 从 JavaScript 函数获取 NaN 尝试多次获取相同的数据
- 从 JS 函数获取 PHP 中的值
- 如何用一个函数获取所有javascript变量
- Javascript-函数获取数组元素参数未定义/为null
- 从回调函数获取xhr状态
- 有没有一种方法可以让watch函数获取被监视文件的名称
- 从JQuery到Javascript函数获取表单对象
- 使用react.js从api函数获取json数据
- 从javascript中的递归函数获取undefined
- 使用sails.js中的beforeConnect函数获取客户端套接字
- 如何通过类名和过滤函数获取属性值
- 从php函数获取值到javascript
- 从外部函数获取参数名称
- 从方法js中的函数获取对象属性
- 使用Jquery.load()函数获取变量和页面片段
- 使用onclick函数获取点击的元素jquery