Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

fabioi's avatar

[SOLVED] Help needed - Cannot set datatables width

Hello,

I am using datatables in a Laravel app using https://github.com/yajra/laravel-datatables-oracle. The issue is that I cannot resize the columns.

This is the code I am using:

#css imports

#js imports

#the html

 <table id="users" class="table table-hover table-condensed">
            <thead>
            <tr>
                <th class="col-md-3">{{{ trans('users.id') }}}</th>
                <th class="col-md-3">{{{ trans('users.first_name') }}}</th>
                <th class="col-md-3">{{{ trans('users.last_name') }}}</th>
                <th class="col-md-3">{{{ trans('users.email') }}}</th>
                <th class="col-md-3">{{{ trans('users.confirmed') }}}</th>
                <th class="col-md-3">{{{ trans('users.suspended') }}}</th>
                <th class="col-md-3">{{{ trans('users.roles') }}}</th>
                <th class="col-md-3">{{{ trans('users.created_at') }}}</th>
                <th class="col-md-3">{{{ trans('formFields.actions') }}}</th>

            </tr>
            </thead>
            <tbody>
            <tr>
                <th class="col-md-3">{{{ trans('users.id') }}}</th>
                <th class="col-md-3">{{{ trans('users.first_name') }}}</th>
                <th class="col-md-3">{{{ trans('users.last_name') }}}</th>
                <th class="col-md-3">{{{ trans('users.email') }}}</th>
                <th class="col-md-3">{{{ trans('users.confirmed') }}}</th>
                <th class="col-md-3">{{{ trans('users.suspended') }}}</th>
                <th class="col-md-3">{{{ trans('users.roles') }}}</th>
                <th class="col-md-3">{{{ trans('users.created_at') }}}</th>
                <th class="col-md-3">{{{ trans('formFields.actions') }}}</th>

            </tr>
            </tbody>

            <tfoot>
            <tr>
                <th class="col-md-3">{{{ trans('users.id') }}}</th>
                <th class="col-md-3">{{{ trans('users.first_name') }}}</th>
                <th class="col-md-3">{{{ trans('users.last_name') }}}</th>
                <th class="col-md-3">{{{ trans('users.email') }}}</th>
                <th class="col-md-3">{{{ trans('users.confirmed') }}}</th>
                <th class="col-md-3">{{{ trans('users.suspended') }}}</th>
                <th class="col-md-3">{{{ trans('users.roles') }}}</th>
                <th class="col-md-3">{{{ trans('users.created_at') }}}</th>
                <th class="col-md-3">{{{ trans('formFields.actions') }}}</th>

            </tr>
            </tfoot>
        </table>

#the datatable initialization


oTable = $('#users').DataTable({

            initComplete: function () {

            tableTools: {
                "sSwfPath": "/custom/datatables_table_tools2_2_4/swf/copy_csv_xls_pdf.swf",
                "sRowSelect": "multi",
                "aButtons": [ 'copy' ]
            },
            "processing" :  true,
            "dom": '<"toolbar"fT>rtip', 
            "autoWidth": false,
            "ajax": "api",

            "language"  :
            {
                "url":
                baseDataTablesLangCDNPath + langFile
            },
            "columns":
                    [
                        {data: 'id',  name: 'users.id', "visible": false ,"width": "5%" },
                        {data: 'name',  name: 'user_profiles.name',"width": "5%" },
                        {data: 'surname', name: 'surname' ,"width": "5%" },
                        {data: 'email', name: 'email' ,"width": "5%" },
                        {data: 'confirmed', name: 'confirmed'  ,"width": "5%"},
                        {data: 'suspended', name: 'suspended' ,"width": "5%" },
                        {data: 'rolenames', name: 'roles.name' , "width": "5%" },
                        {data: 'created_at', name: 'users.created_at', "width": "5%"  },
                        {data: 'actions', "searchable":false, "orderable": false, name: 'actions' , "width": "20%"},
                    ]
        });

Any idea how to solve the problem?

0 likes
5 replies
mstnorris's avatar
Level 55

@fabioi you're setting the table column width to be col-md-3. That's your problem. Bootstrap is doing its thing.

1 like
fabioi's avatar

Thanks very much!! The classic stupid mistake under the nose :-D You saved my day. Thanks really much again!

toniperic's avatar

@fabioi no need to edit the thread name and add [SOLVED] to it. Just mark an accepted answer and a green tick will appear on the thread listing, which tells people it has been solved.

1 like

Please or to participate in this conversation.