背景资料。
我有一个jquery数据表工作正常...除了我的页面/表格渲染后...它缺少一个行ID。 我需要每一行看起来像这样:
<tr id=10100... > ... </tr>
代码
$(document).ready(function() {
var selected = [];
$('#users').DataTable( {
"processing": false,
"serverSide": true,
"ordering": false,
aLengthMenu: [
[10, 25, 50, 100, "-1"], //controls the "Show X entries" drop down on gui
[10, 25, 50, 100, "All"]
],
"ajax": "/cgi-bin/mvspaging_list",
rowId:'pn',
"rowCallback": function( row, data ) {
if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
$(row).addClass('selected');
}
},
"columns":
[
//{ "data": "id" ,"searchable":false},
{ "data": "pn", "searchable":true },
{ "data": "fname",defaultContent:'', "searchable":true},
{ "data": "lname",defaultContent:'',"searchable":true},
{ "data": "grp_name",defaultContent:'',"searchable":true},
{ "data": "description",defaultContent:'',"searchable":true},
{ "mRender": function ( data, type, row) {
if (row.grp == 0) {
action = '<a href=pndetails.html?pn=' + row.pn +'>Details</a>';
var fullname= encodeURI(row.fname + " " + row.lname);
action = action + ' | ' + '<a href="#" onclick=delpn(' + row.pn + ',"' + fullname + '",false)>Delete</a>';
return action;
} else {
var groupname= encodeURI(row.grp_name);
action = '<a href=group_details.html?pn=' + row.pn +'>Details</a>';
action = action + ' | ' + '<a href="#" onclick=delpn(' + row.pn + ',"' + groupname + '",true)>Delete</a>';
return action;
}
}
}
]
});
} );
目前,这会生成如下的HTML行:
<tr role="row" class="odd">
<td>10100</td>
<td>Devin</td>
<td>Daster</td>
<td></td>
<td></td>
<td><a href="pndetails.html?pn=10100">Details</a> | <a href="#" onclick="delpn(10100,"Devin%20Daster",false)">Delete</a></td>
</tr>
我想指定
rowId:'pn',
可以做到这一点,但我猜不是。
任何有关我缺少的建议都将不胜感激。我目前正在使用此作为参考:https://datatables.net/reference/option/rowId
答案 0 :(得分:1)
我像这样添加/更改了我的电话:
"rowCallback": function( row, data ) {
console.log(data);
$(row).attr('id', data.pn);
},