DataTables jQuery插件nowrap for Ajax表

DataTables jQuery插件nowrap for Ajax表,jquery,datatables,Jquery,Datatables,有人能给我举个例子,说明当ajax表的所有信息都是动态生成时,如何向列添加nowrap=“nowrap” $('#results').dataTable({ "fnRowCallback": function( nRow, aData, iDisplayIndex ) { $(nRow).attr('id', aData[0]); return nRow; }, "bAutoWidth": false, "sPaginationTy

有人能给我举个例子,说明当ajax表的所有信息都是动态生成时,如何向列添加nowrap=“nowrap”

$('#results').dataTable({
    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
        $(nRow).attr('id', aData[0]);
        return nRow;
    },
    "bAutoWidth": false,
    "sPaginationType": "full_numbers",  
    "bProcessing": true,
    "sAjaxSource": 'ajax/purchasers.php',
    "aaSorting": [[1,'asc']],                   
    "aoColumns": [                              
        { "bVisible": false },                      
        null,                                   
        null,
        null,
        null,
        null,
        null,
        null
    ]
});

我知道这可能不太可能。提前感谢。

如果有人对该解决方案感兴趣,您可以在DataTables完成渲染后使用FNINTComplete在表上循环:

$('#results').dataTable({
    "fnInitComplete": function() {
        $('#results tbody tr').each(function(){
                $(this).find('td:eq(0)').attr('nowrap', 'nowrap');
        });
    },
    "sAjaxSource": 'ajax/purchasers.php'
});

如果有人对解决方案感兴趣,可以在DataTables完成后使用fnInitComplete在表上循环,如下所示:

$('#results').dataTable({
    "fnInitComplete": function() {
        $('#results tbody tr').each(function(){
                $(this).find('td:eq(0)').attr('nowrap', 'nowrap');
        });
    },
    "sAjaxSource": 'ajax/purchasers.php'
});

最好通过造型来实现这一点

"aoColumns": [                              
    { "sClass": "my_class"},
在样式表中

    .my_class {
   white-space:nowrap;
 }

最好通过造型来实现这一点

"aoColumns": [                              
    { "sClass": "my_class"},
在样式表中

    .my_class {
   white-space:nowrap;
 }

虽然添加一个类并为此创建一个CSS条目肯定是可行的,但它看起来像是在用锤子敲打螺丝钉

Datatables已经提供了一种简单的方法

在dataTable声明中添加:

"fnRowCallback": function( nRow ) {
    if(nRow.cells[2]) nRow.cells[2].noWrap = true;  // column index starts with 0 and we check if cells[2] is null to be ultra safe
    return nRow;
},

希望这会有所帮助,虽然添加一个类并为此创建CSS条目肯定会有用,但这就像是用锤子敲入螺丝钉一样

Datatables已经提供了一种简单的方法

在dataTable声明中添加:

"fnRowCallback": function( nRow ) {
    if(nRow.cells[2]) nRow.cells[2].noWrap = true;  // column index starts with 0 and we check if cells[2] is null to be ultra safe
    return nRow;
},

希望这有助于

在使用分页和测试jeerose的方法时,只有表的第一页获得指定的属性。。。因此,使用aoColumns设置样式是一个更好的选择。在使用分页和测试jeerose的方法时,只有表的第一页获得指定的属性。。。因此,使用aoColumns设置样式是一个更好的选择。jeerose的帖子需要外部(到datatables)javascript,Karthik的帖子需要外部(到datatables)css。jeerose的文章需要外部(到dataTables)javascript,Karthik的文章需要外部(到dataTables)css。这应该可以很好地处理dataTables试图做的任何事情。请从性能的角度查看我的答案,以获得更好的解决方案。当您可以在初始化期间添加一个简单的css类时,您可能不想在整个表上循环。对大量行尝试这两个选项。如果你不是在处理大量的行,你可能没问题。解决方案是使用CSS!请从性能的角度查看我的答案,以获得更好的解决方案。当您可以在初始化期间添加一个简单的css类时,您可能不想在整个表上循环。对大量行尝试这两个选项。如果你不是在处理大量的行,你可能没问题。解决方案是使用CSS!