Column Size with Datatables

Asked

Viewed 5,980 times

0

I’m using the plugin DataTables to paginate a record in a panel. The problem is that this table has 5 columns, the last one is called action where there are 4 links (currently one below the other because of the size of the column). I would like to augment the size of this column so that it is at least 2 in each row, I would only need to increase even the column size. I currently have the following code:

$('#table-clientes').DataTable( {
                    "ajax": baseURL,
                    "deferRender": true,
                    "order": [[ 0, "asc" ]],
                    "pageLength": 300,
                    "columnDefs": [
                        { "width": "50%", "targets":4 }
                      ]
                } );

When loading the page, the column ação gets the size I want, but when it’s finished loading, it goes back to its tiny size. I’ve tried putting classin columnDefs and then on css use width: 40% ! Port but nothing helped.

  • Try to set the size of the others too, I already did this once in the datatables and it only accepted when I set the size of all columns independently.

  • The HTML order is correct?

  • Yes, I even let it go actually. It wasn’t so necessary. Thank you in the same way!

3 answers

2

Try the following:

$('#table-clientes').DataTable( {
                    "ajax": baseURL,
                    "deferRender": true,
                    "order": [[ 0, "asc" ]],
                    "pageLength": 300,
                    "columnDefs": [
                        { "title": "Nome do Cliente", "data": "NOMECLIENTE" "width": "50%"}
                      ]
                } );

Where

"title": "Nome do Cliente" (O titulo que exibira na sua table)
"data": "NOMECLIENTE" (Como você chama o campo do BD)
"width": "50%" (O tamanho que v)

0

The only way it worked for me was:

Add the CSS below

#table-clientes{
    table-layout: fixed !important;
    word-wrap:break-word;
}

And in HTML put the percentage, example:

    <th style='width: 5%;'>Coluna 1</th>
    <th style='width: 15%;'>Coluna 2</th>
    <th style='width: 40%;'>Coluna 3</th>
    <th style='width: 20%;'>Coluna 4</th>
    <th style='width: 10%;'>Coluna 5</th>
    <th style='width: 10%;'>Coluna 6</th>
</tr>

This response was inspired by the responses of this post: https://stackoverflow.com/posts/51674965/edit

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.