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

[Bug Report] Data-table headers width doesn't work #5072

Closed
vcastro45 opened this issue Sep 11, 2018 · 28 comments · Fixed by #8296
Closed

[Bug Report] Data-table headers width doesn't work #5072

vcastro45 opened this issue Sep 11, 2018 · 28 comments · Fixed by #8296
Assignees
Labels
C: VDataTable S: has PR The issue has a pending Pull Request T: bug Functionality that does not work as intended/expected T: enhancement Functionality that enhances existing features

Comments

@vcastro45
Copy link

Versions and Environment

Vuetify: 1.2.2
Vue: 2.5.17
Browsers: Chrome 69.0.3497.81
OS: Windows 10

Steps to reproduce

Create a data-table and add a "width" attribute to a header object

Expected Behavior

The column corresponding to the header object with the "width" attribute must have the desired width.

Actual Behavior

The width attribute is added to the DOM but this HTML attribute is deprecated for HTML5 and does nothing (cf: https://www.w3schools.com/TAGS/att_th_width.asp)

Reproduction Link

https://codepen.io/anon/pen/wEyZwN?editors=1010

Other comments

The suggested work-around provided by W3C that say to use the "width" CSS property doesn't work for this component.

@bestickley
Copy link

bestickley commented Sep 12, 2018

If you remove the <v-flex> from your codepen it works.
I had a similar problem where the width I set in my headers array wasn't affecting the columns. The fix I found was increasing the width on the <v-card> component my datatable was inside of

@johnleider johnleider added T: bug Functionality that does not work as intended/expected T: enhancement Functionality that enhances existing features labels Sep 15, 2018
@WhatFreshHellIsThis
Copy link

Yes, removing the v-flex around it fixes the issue but then the whole layout is broken!? What to do?

@ghost
Copy link

ghost commented Feb 7, 2019

I am not using v-flex, but it doesn't work either!

<template>
    <div>
        <v-container class="my-5">
            <v-data-table></v-data-table>
        </v-container>
    </div>
</template>

Inside headers I tried to set width as follows: width: '20%', width: '100px', width: '150', but none of them had an impact on the data tables header width

@wobsoriano
Copy link

wobsoriano commented Feb 16, 2019

@saitam1 Do you have a fix for this already? Adding width keys to the headers array is not working. Setting a class also is not working. This is a long time issue already.

I hope someone share their solution...

@CodeMonkeyG
Copy link

I spent hours fighting this today. Nearly lost my mind. The fix for me?

<v-data-table class="my-awesome-table"></v-data-table>

<style>
  .my-awesome-table{
    table-layout : fixed;
  }
</style>

Suddenly the widths in the header configs were honored.

@360hnjd-fe
Copy link

Not repaired yet?

@huynd8295
Copy link

I have the same problem, the width attribute doesnt seem to work at all.

@guastallaigor
Copy link
Contributor

Same here, table-layout: fixed didn't work in my case for some reason. Any other workaround?

@laurengranada
Copy link

My Before:
before

My After:
after

my code:

<v-data-table ... class="mi-dataTable elevation-1">
    <template slot="headers" slot-scope="props">
         <tr class="mid-headercell">
             <th class="midh-text"  v-for="header in props.headers"
                >{{header.text}}
             </th>
         </tr>
     </template>
     <template v-slot:items="props">
           <td class-"mid-item">{{props.item.desc}}</td>
            ....
    </template>
</v-data-table>

and the css that fixed my problem!:

table-layout: fixed as well as the padding: 0px for my headercell

.mi-dataTable{
     table-layout: fixed;
     .mid-headercell{
            text-align: left;
            background-color: $blue_accent;
            .midh-text{
                    padding: 0px;
                    padding-left: 2.5%;
                    color: white;
                    font-weight: 400;
             }
      }
}

Hope this helps someone else!

@hlohrenz
Copy link

hlohrenz commented Apr 26, 2019

So the thing that solved it for me was adding this styling to the th tags inside the table's header:

table.v-table
  thead
    th
      white-space: normal // Default was nowrap which was causing the headers to not shrink down

My width's were then respected.

headers: [
  { text: 'Account', value: 'name', sortable: true, width: '20%' },
  { text: 'Type', value: 'deliverable', sortable: true, width: '20%' },
  { text: 'Progress', value: 'progress', sortable: true, align: 'center', width: '10%' },
  { text: 'Delivery Date', value: 'design_delivered_at', sortable: true, align: 'center', width: '5%' },
  { text: 'Research or Design Rating', value: 'ratings', sortable: false, align: 'center', width: '20%' },
  { text: 'Reported Revenue', value: 'dollars', sortable: true, align: 'center', width: '10%' },
  { text: 'View', value: 'name', sortable: false, align: 'center', width: '5%' },
  { text: 'Request Edits', value: 'name', sortable: false, align: 'center', width: '5%' },
  { text: 'Created For', value: 'name', sortable: false, align: 'center', width: '5%' }
]

@getsong
Copy link

getsong commented May 14, 2019

This works for me:

headers: [
          {value: 'index', text: '#', sortable: false, width: '5%'},
          {value: 'id', text: 'Id', width: '5%'},
          {value: 'headerA', text: 'headerA', width: '10%'},
          {value: 'headerB', text: 'headerB', width: '10%'},
          {value: 'headerC', text: 'headerC', width: '12%'},
          {value: 'headerD', text: 'headerD', width: '12%'},
          {value: 'headerE', text: 'headerE', width: '6%'},
          {value: 'headerF', text: 'headerF', width: '12%'},
          {value: 'headerG', text: 'headerG', width: '18%'}
]

Here is the css that make it work:

<style>
  .class-on-data-table table {
    table-layout: fixed;
  }
</style>

css <style> should not be scoped in order to style the table element, which is a in child component.

@ricardovanlaarhoven
Copy link
Contributor

Will this issue get fixed for 1.5 or only 2.0 ?

@allochi
Copy link

allochi commented May 22, 2019

It doesn't work for me too, I had to wrap the content with a div and set its width with a style

<td>
    <div style="width: 300px">...</div>
</td>

not the best solution, but it works for now.

@WhatFreshHellIsThis
Copy link

Serious bug in major component over 8 months old now, can this be prioritized higher?

@nekosaur
Copy link
Member

Prioritization happens based on the availability of contributors. PRs are always welcome.

@Oscarz90
Copy link

Oscarz90 commented Jul 5, 2019

It doesnt work, I've tried many of the options published here

@nekosaur
Copy link
Member

Repro in 2.0 https://codepen.io/gilderbairn/pen/rXOyWL

nekosaur added a commit that referenced this issue Aug 4, 2019
setting both width and min-width as styles on header row was the only
way I could get a consistent result

closes #5072
@nekosaur nekosaur added the S: has PR The issue has a pending Pull Request label Aug 4, 2019
johnleider pushed a commit that referenced this issue Aug 12, 2019
setting both width and min-width as styles on header row was the only
way I could get a consistent result

closes #5072
closes #7623
@klaveren
Copy link

klaveren commented Oct 31, 2019

I have used windows size to fix this problem.

vue:
<v-container v-resize="onResize"> <v-card :width="windowSize.x"> <v-data-table /> </v-card> </v-container>

js:
data() { return { search: '', headers: [], windowSize: { x: 0, y: 0, } } }, mounted () { this.onResize() }, methods: { onResize () { this.windowSize = { x: window.innerWidth, y: window.innerHeight } } }

@kajirikajiri
Copy link

<td style="min-width:55px;width:55px;max-width:55px"></td>

@ijunaid8989

This comment has been minimized.

@ElSamhaa
Copy link

ElSamhaa commented Oct 8, 2020

why has this been closed?

@jacekkarczmarczyk
Copy link
Member

Because it's fixed

We kindly ask users to not comment on closed/resolved issues. If you believe that this issue has not been correctly resolved, please create a new issue showing the regression or reach out to us in our Discord community.

Thank you for your contribution and interest in improving Vuetify.

@ElSamhaa
Copy link

ElSamhaa commented Oct 8, 2020

@jacekkarczmarczyk sorry to bother you, but in my own experience, the issue was not resolved even once and I don't think this is a regression. I am still experiencing the non-honored widths without the suggested table-layout: fixed.

I'll post a working link to my code.

@iec989
Copy link

iec989 commented Oct 28, 2020

Same thing here, it doesn't look like it's been solved

@jacekkarczmarczyk
Copy link
Member

#5072 (comment)

@nmalchy

This comment has been minimized.

@truemoroz
Copy link

#5072 (comment)

It's not fixed at all. Show working example, please

@jacekkarczmarczyk
Copy link
Member

jacekkarczmarczyk commented May 5, 2021

not working: #5072 (comment)
working: https://codepen.io/jkarczm/pen/bGqbJpj

image

If you believe that this issue has not been correctly resolved, please create a new issue showing the regression or reach out to us in our Discord community.

@vuetifyjs vuetifyjs locked as resolved and limited conversation to collaborators May 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C: VDataTable S: has PR The issue has a pending Pull Request T: bug Functionality that does not work as intended/expected T: enhancement Functionality that enhances existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.