阿贾克斯表数据表jQuery插件NOWRAP(DataTables jQuery plugin no

2019-10-19 16:51发布

有人可以给我如何添加NOWRAP =“NOWRAP”一列的例子,当在运行一个AJAX表中生成的所有信息?

$('#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
    ]
});

我知道这可能是一个长镜头。 提前致谢。

Answer 1:

这是更好地通过造型,而不是实现这一目标。

"aoColumns": [                              
    { "sClass": "my_class"},

在样式表

    .my_class {
   white-space:nowrap;
 }


Answer 2:

虽然它肯定将努力增加一类,并为此创建的CSS项,好像用锤子在螺杆砸向。

数据表已经为此提供了一个简单的方法。

在你的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;
},

希望这可以帮助



Answer 3:

如果有人有兴趣的解决方案,可以在桌子上使用fnInitComplete循环数据表做渲染它像这样经过:

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


文章来源: DataTables jQuery plugin nowrap for Ajax table