0

I'm using Datatables. Columns have auto width, I want to make their width smaller. I tried some things, but it doesn't change. My table is:

$(document).ready(function () {
    $('#example').dataTable({
        "pagingType": "full_numbers",
            "bSort": true,
            "sDom": 'T<"clear">lfrtip',
            "tableTools": {
            "sSwfPath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf",
                "aButtons": [
                    "csv",
                    {
                        "sExtends": "pdf",
                        "sButtonText": "Print PDF",
                        "mColumns": "visible"
                    },
                    "xls"
                ]
            },

        },
        "columnDefs": [{
            "width": "5%"
        }]
    });
});

1 Answer 1

1

Examples

Set the first column's width to 20% with columnDefsDT:

$('#example').dataTable( {
  "columnDefs": [
    { "width": "20%", "targets": 0 }
  ]
} );

Set the first column's width to 20% with columnsDT:

$('#example').dataTable( {
  "columns": [
    { "width": "20%" },
    null,
    null,
    null,
    null
  ]
} );
Sign up to request clarification or add additional context in comments.

1 Comment

I tried with the second and it changes, but table doesn't look like Datatable - it disappears sorting in head of the tables and search in foot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.