Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在DataTables 1.10.x中设置td id/名称的问题_Javascript_Jquery_Datatables - Fatal编程技术网

Javascript 在DataTables 1.10.x中设置td id/名称的问题

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;">'+

这与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;">'+                
        '<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
设置一个类a
td
,如图所示,但我不知道如何添加其他条件,我需要为生成的每个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;
        }
    }],
});