Columns not adjusting

Columns not adjusting

k_poehlerk_poehler Posts: 3Questions: 1Answers: 0
edited February 2016 in Free community support

Hi, I'm importing a full table pre-drawn from ajax, but when applying dataTable all columns and even the table shrink to its minimum witdh. This is what I'm using:

$("#tabla").DataTable({
                "scrollX": true,
                "scrollCollapse":true,
                "sort": false,
                "sDom": 'Tt',
                "tableTools": {
                    "sSwfPath": "../js/plugins/DataTables-1.10.2/extensions/TableTools/swf/copy_csv_xls_pdf.swf",
                    "aButtons": [
                        "copy",                               
                        "xls",
                        {
                            "sExtends": "pdf",
                            "sPdfOrientation": "landscape",
                            "sPdfMessage": "mensaje",
                            "sTitle": "Titulo"
                        }
                    ]
                }
            });

This question has an accepted answers - jump to answer

Answers

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    Try adding below to your config, this might be causing your issue.

    "autoWidth: false
    

    https://datatables.net/reference/option/autoWidth

    Outside of this, would need to see what the table HTML looks like to better be able to assist you.

  • k_poehlerk_poehler Posts: 3Questions: 1Answers: 0

    @jr42.gordon Thank you, I've tryed to do that though it didn't worked. In the end I ended up solving it doing:

    setInterval(function(){
                    t.columns.adjust();
                },0);
    

    but I would still know why the need to do this, so my table looked like :

    <table class="table table-striped table-bordered table-hover table-condensed view-table">
        <thead>
            <th>Producto</th>
            <th>Clase Diam&eacute;trica</th>
            <th>Destino</th>
            <th>Equipo</th>
        </thead>
        <tbody>
            <tr>
                <td align="center">P0320APDC</td>
                <td align="center">16 - 40</td>
                <td align="left">&nbsp;CN TRANSFERENCIA ASERMAIN</td>
                <td align="left">&nbsp;<p class='pill pill-red action' onclick='mostrarDetalle(33250)'>TG-00317</p></td>
            </tr>
        </tbody>
    </table>
    
  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49
    Answer ✓

    That was going to be my next suggestion. When you initialize your DataTable, is it visible? If not, then that is why that code is needed. DataTables doesn't know the dimensions of its container as it isn't visible.

  • k_poehlerk_poehler Posts: 3Questions: 1Answers: 0

    @jr42.gordon Really Thank you, you're right, when initialized is hidden. I though for a moment it could be something related to that, but fixing it was more troublesome than the other.

This discussion has been closed.