columnDefs width Not Working

columnDefs width Not Working

Ninja JoeNinja Joe Posts: 15Questions: 7Answers: 1
edited April 2022 in Free community support

I have a three-column table on which I'm trying to change the second column's width to 400 pixels. However, my columnDefs is having no effect. I'm wondering why it isn't working? Could it be because I'm loading JSON data or another reason?

Here's my DataTable() call:

$( '#ajax-datatable').DataTable( { ajax:{ url: 'https://example.com/json', dataSrc:'' }, "columns": [ { "data": "id" }, { "data": "status" }, { "data": "permit" } ], scrollX: true, pageLength: 10, pagingType: 'full_numbers',
    columnDefs: [
        { targets: [ 1 ], width: '400px' }, // <-- Not working.
        { targets: '_all', className: 'dt-center' } // <-- Working.
    ],

    drawCallback: function() {
        $( '.dataTables_paginate > .pagination' ).addClass( 'pagination-rounded' );
    }
} );

The curious thing is, { targets: '_all', className: 'dt-center' } DOES work.
I tried doing { targets: '_all', width: '400px' } but it also didn't work.

This question has an accepted answers - jump to answer

Answers

  • Ninja JoeNinja Joe Posts: 15Questions: 7Answers: 1
    edited April 2022 Answer ✓

    Found the answer: I needed to remove the "w-100" Bootstrap class from the table element.

Sign In or Register to comment.