Javascript 在DataTables 1.10.x中设置td id/名称的问题
这与datatables 1.10.x有关 我使用引用创建子行,很容易将HTML放入生成的javascript代码中,如下所示:Javascript 在DataTables 1.10.x中设置td id/名称的问题,javascript,jquery,datatables,Javascript,Jquery,Datatables,这与datatables 1.10.x有关 我使用引用创建子行,很容易将HTML放入生成的javascript代码中,如下所示: function format ( d ) { return '<div class="slider">'+ '<table id="expandInput" cellpadding="5" cellspacing="0" border="0" style="margin: 0 auto;">'+
function format ( d ) {
return '<div class="slider">'+
'<table id="expandInput" cellpadding="5" cellspacing="0" border="0" style="margin: 0 auto;">'+
'<tr>'+
'<td class="dropHeader">Cost</td>'+
'<td class="dropInfo"><input required type="text" id="cost" name="cost" value="'+d.cost+'"></input></td>'+
'</tr>'+
'</table>'+
'</div>';
}
我知道我可以使用columnDefs
设置一个类atd
,如图所示,但我不知道如何添加其他条件,我需要为生成的每个td设置一个唯一的id
和name
。每当为表体创建TR元素时,都需要使用属性来定义回调
$('#example').dataTable( {
"createdRow": function ( row, data, index ) {
$('td', row).eq(1).attr('id', 'td-' + index + '-1');
}
});
代码$('td',行)。等式(1)
用于使用基于零的索引选择表行中的第二个单元格(1
用于第二个单元格)。Codeattr('id','td-'+index+'-1')
将第一行的单元格id
属性设置为td-0-1
,第二行的单元格td-1-1
等,其中index
是基于零的行索引
请参阅或进行演示。在我的示例中,它与“rowData”一起工作。一些代码:
$('#example').dataTable({
"columnDefs": [{
'targets': [4], 'createdCell': function (td, cellData, rowData, row, col) {
td.id = "ID_For_TD_" + rowData.ObjId;
}
}],
});
$('#example').dataTable({
"columnDefs": [{
'targets': [4], 'createdCell': function (td, cellData, rowData, row, col) {
td.id = "ID_For_TD_" + rowData.ObjId;
}
}],
});