Strange behaviour when I asign witdh dinamically

Strange behaviour when I asign witdh dinamically

DarkxemnasDarkxemnas Posts: 5Questions: 3Answers: 0

Hi people!
I've been working with DataTablese around 3 months, and today I've founded a strange behaviour. Let me explain the situation:

First, I assign dinamically the width throught json and javascript variables, specifically colWidth and columnTitle.

colWidth give me the value of the variable that is sended throught json.
columnTitle retrieves the longside of the characters that the TH of the table has. ( Ex : "Hello" = 5).

The width for the column is determined by this formula :
If the columnTitle is bigger than colWidth, I assign the (columnTitle * somenumber) to the colWidth.

Then, I just put the columns: { "width": colWidth }. And this works almost perfectly! But when I try to rewidth the columns, the plugin automatically assigns more width than the formula has calculated. I checked that the width that json sends doesn't change, so...

Somebody can help me, please?

Variables :

var domColumns = document.querySelectorAll( this.dataTableName +" th"),
columns = [];

for (var i = 0; i< domColumns.length; i++ ) {
        colWidth = domColumns[i].dataset.colwidth,
        columnTitle = domColumns[i].innerText.trim().length,

Datatable creation:

me.dataTableName =  dataTableName;
me.datTableObject = $( this.dataTableName ).DataTable({
    "iDisplayLength": 25,
    "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'hidden-xs col-sm-6'lC>r>"+
            "Zt"+
            "<'dt-toolbar-footer'<'hidden-xs col-sm-6'i><'col-xs-12 col-sm-6'p>>",
    "fnInitComplete": function() {
       this.removeClass("hidden");
       $(me.dataTableName).wrap( "<div class='tableWrap'></div>" );
    },
    "autoWidth" : false,
    "bAutoWidth": false,
    "columns": columns,
    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) 
    {
        if (!me.datTableObject)
            return;     

        var metadata = me.datTableObject.metadata

        if (metadata) {
            me.colorTable(metadata, nRow, iDisplayIndexFull);
        };
    }
});    

Assignment:

    colWidth = Math.min(colWidth, 100);



    if (colName == "rowid") {
         columns.push({
            "visible": false,
            "width": colWidth,
            "className" : className
         })

    } else {
        columns.push({
            "width": colWidth,
            "className" : className
        })
    }
This discussion has been closed.