删除DataTables列中的额外填充 [英] Removing extra padding in DataTables columns

查看:72
本文介绍了删除DataTables列中的额外填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我已经创建了如下所示的JQuery DataTables:

Hi so I have created JQuery DataTables that looks like this:

所以我的问题是如何在PICTURE列中删除过多的填充?

So my question is how to remove that too much padding in the "PICTURE" column?

这是我初始化表格的方式:

This is how I initialize the table:

$('#violators_tbl').DataTable({
            "aoColumnDefs": [
                { "bSortable": false, "aTargets": [ 2,3 ] },
                { "sWidth": "20%", "aTargets": [ 0 ] },
                { "sWidth": "35%", "aTargets": [ 1 ] },
                { "sWidth": "30%", "aTargets": [ 2 ] },
                { "sWidth": "15%", "aTargets": [ 3 ] },
            ],
        });

这是我向表中添加行的方式:

This is how I add rows to the table:

function update_table(violator){
        var img_str1 = '<img class=\"obj-pic\" src=\"' + Main.Vars.base_path + violator.front_temp_file_path + '\">';
        var img_str2 = '<img style=\"margin-left: 10px;\" class=\"obj-pic\" src=\"' + Main.Vars.base_path + violator.rear_temp_file_path + '\">';
        var img_str3 = '<img style=\"margin-left: 10px;\" class=\"obj-pic\" src=\"' + Main.Vars.base_path + violator.right_temp_file_path + '\">';
        var img_str4 = '<img style=\"margin-left: 10px;\" class=\"obj-pic\" src=\"' + Main.Vars.base_path + violator.left_temp_file_path + '\">';
        violators_table.dataTable().fnAddData([
            violator.violator_id,
            violator.get_full_name(),
            'Under Construction',
            img_str1 + img_str2 + img_str3 + img_str4,
        ]);
    }


推荐答案

更简单的方法是添加 sClass 选项,它将类添加到指定的列。此后,您可以根据需要设置 my_class 的样式。这样,只有特定的表实例受到影响,而不是您应用程序中的其他实例。

Easier way would be to add the sClass option which adds a class to the designated columns. Thereafter, you can style your my_class according to your needs. This way, only the specific table instance is affected and not the others in your application.

$('#violators_tbl').dataTable({
    "aoColumnDefs": [
      { "sClass": "my_class", "aTargets": [ 0 ] }
    ]
  } );

这篇关于删除DataTables列中的额外填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆