Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Width of column #2033

Open
djdony opened this issue Mar 23, 2019 · 10 comments
Open

Width of column #2033

djdony opened this issue Mar 23, 2019 · 10 comments

Comments

@djdony
Copy link

djdony commented Mar 23, 2019

Summary of problem or feature request

Hi. i can not set width for column Age. I tried to change in head

     <table class=" table-bordered table-hover" id="employeesTable">
            <thead>
            <th></th>
                <th>{{trans('messages.first_name')}}</th>
                <th>{{trans('messages.last_name')}}</th>
            <th width="10%">{{trans('messages.age')}}</th>

But still does not apply width.

Code snippet of problem

$(document).ready(function(){

    var table = $('#employeesTable').DataTable({
        processing: true,
        serverSide: true,
        ajax: '{{ route("pim.employees.datatable")}}',
        bAutoWidth:false,
        columns: [
            {data: 'first_name'},
            {data: 'last_name'},
            {data: 'birthdate',sWidth:'5%'},
            {data: 'actions', sortable: false, searchable: false},

        ],

System details

  • Operating System Ubuntu
  • PHP Version 7
  • Laravel Version 5.8
  • Laravel-Datatables Version 9.0
@rahul-chavda
Copy link

hello , this documentation might help.

@djdony
Copy link
Author

djdony commented Mar 24, 2019

I read the documentations, tried parameters width in column, but still can not set width.

I used inline style but table autowided itself.
autoWidth: false, not working at all.

@rahul-chavda
Copy link

what datatable version you are using ?

@djdony
Copy link
Author

djdony commented Mar 24, 2019

9.0 last version. bootstrap 4

@rahul-chavda
Copy link

hey, @djdony I guess the problem is you have written columns instead of aoColumns.
I have tested this and it is working.
code pen
stack overflow reference

@mariopro
Copy link

mariopro commented May 5, 2023

The ->width() method applies a width attribute to the th which is no longer supported in modern HTML, meaning that setting the ->width(200) or ->with('200') when used in the Column::make() has no effect when rendering the column. I've tried adding the width using the ->addClass() method and using the framework width styling, and nothing changes, even when setting ->autoWidth(false).
Humble suggestion: create a method for inline styling ->addStyle() that would solve most related issues and even add more customization ability.
Using V10.4.0

@yajra
Copy link
Owner

yajra commented May 6, 2023

@mariopro thanks for the info about width, not aware of it.

You can already add a style using the magic method since Column is a Fluent class. But it would be nice to add a method for better IDE support.

Column::make('name')->style('width: 150px; color: red'),

@mariopro
Copy link

mariopro commented May 6, 2023

@mariopro thanks for the info about width, not aware of it.

You can already add a style using the magic method since Column is a Fluent class. But it would be nice to add a method for better IDE support.

Column::make('name')->style('width: 150px; color: red'),

Thanks @yajra for your prompt reply. That's great news and in fact works, yet as you say, IDE does not recognize the method. Nevetheless, it works :) Thank you!

@github-actions
Copy link

github-actions bot commented Jun 6, 2023

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Jun 6, 2023
@yajra yajra added enhancement and removed stale labels Jun 7, 2023
@kingzamzon
Copy link

I solved it this way by using editColumn and creating a blade file with a static width

DataTable file (e.g GDPBeneficiariesTrainedDataTable):

class GDPBeneficiariesTrainedDataTable extends DataTable
{
    public function dataTable($query)
    {
        return datatables()
            ->eloquent($query)
            ->addIndexColumn()
            ....
            ->editColumn('shg_id', function ($data) {
                $data['value'] = $data->shg_id;
                $data['width'] = "200px";
                return view('datatables.width-column', $data);
            })
            ....
    }
    ....

Blade file (e.g datatables.width-column)

<div cstyle="width:{{$width}}">
    {{ $value}}
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants