Changing DataTable cell width

Problem:

If only a few columns, the space is too big.

$tblContainer.html("<table class='dataTable striped border hovered'></table>");
var reportName = JSON.parse(this.data).ReportName;
if (reportName.indexOf("Automation")>-1) {
    table = $tblContainer.DataTable({
        "bSort": false,
        "createdRow": function (row, data, dataIndex) {
            if (data[0].indexOf("<b>") > -1) {
                $(row).addClass('header-lightblue');
            }
            row.cells[0].width = '400px';  //first column
            if (data.length < 5) {
                for (var i = 1; i < data.length - 1; i++) {
                    row.cells[i].width = '200px';
                }
            }
        },

 

发表评论