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

fix(VDataTable): max-width doesn work properly, new prop to wrap text when use maxWidth #18961

Merged
merged 1 commit into from Apr 8, 2024

Conversation

websitevirtuoso
Copy link
Contributor

Description

Fix for issue: #18862

Markup:

in this playground use props
maxWidth: '60px',
wrap: true,

<template>
  <v-data-table-server
    v-model:items-per-page="itemsPerPage"
    :headers="headers"
    :items-length="totalItems"
    :items="serverItems"
    :loading="loading"
    item-value="name"
    @update:options="loadItems"
  ></v-data-table-server>
</template>

<script>
const desserts = [
  {
    name: 'Frozen Yogurt,Frozen Yogurt,Frozen Yogurt,Frozen Yogurt,Frozen Yogurt,Frozen Yogurt,Frozen Yogurt,',
    calories: 159,
    fat: 6.0,
    carbs: 24,
    protein: 4.0,
    iron: '1',
  },
  {
    name: 'Eclair',
    calories: 262,
    fat: 16.0,
    carbs: 23,
    protein: 6.0,
    iron: '7',
  },
  {
    name: 'Gingerbread',
    calories: 356,
    fat: 16.0,
    carbs: 49,
    protein: 3.9,
    iron: '16',
  },
  {
    name: 'Ice cream sandwich',
    calories: 237,
    fat: 9.0,
    carbs: 37,
    protein: 4.3,
    iron: '1',
  },
  {
    name: 'Lollipop',
    calories: 392,
    fat: 0.2,
    carbs: 98,
    protein: 0,
    iron: '2',
  },
]

const FakeAPI = {
  async fetch({ page, itemsPerPage, sortBy }) {
    return new Promise(resolve => {
      setTimeout(() => {
        const start = (page - 1) * itemsPerPage
        const end = start + itemsPerPage
        const items = desserts.slice()

        if (sortBy.length) {
          const sortKey = sortBy[0].key
          const sortOrder = sortBy[0].order
          items.sort((a, b) => {
            const aValue = a[sortKey]
            const bValue = b[sortKey]
            return sortOrder === 'desc' ? bValue - aValue : aValue - bValue
          })
        }

        const paginated = items.slice(start, end)

        resolve({ items: paginated, total: items.length })
      }, 500)
    })
  },
}

export default {
  data: () => ({
    itemsPerPage: 5,
    headers: [
      {
        title: 'Dessert (100g serving), Dessert (100g serving)',
        align: 'start',
        sortable: false,
        key: 'name',
        maxWidth: '60px',
        wrap: true,
      },
      { title: 'Calories', key: 'calories', align: 'start' },
      { title: 'Fat (g)', key: 'fat', align: 'end' },
      { title: 'Carbs (g)', key: 'carbs', align: 'end' },
      { title: 'Protein (g)', key: 'protein', align: 'end' },
      { title: 'Iron (%)', key: 'iron', align: 'end' },
    ],
    serverItems: [],
    loading: true,
    totalItems: 0,
  }),
  methods: {
    loadItems({ page, itemsPerPage, sortBy }) {
      this.loading = true
      FakeAPI.fetch({ page, itemsPerPage, sortBy }).then(
        ({ items, total }) => {
          this.serverItems = items
          this.totalItems = total
          this.loading = false
        }
      )
    },
  },
}
</script>

@websitevirtuoso websitevirtuoso changed the title (fix/VDataTable) max-width doesn work properly, new prop to wrap text when use maxWidth fix(VDataTable) max-width doesn work properly, new prop to wrap text when use maxWidth Jan 2, 2024
@websitevirtuoso websitevirtuoso changed the title fix(VDataTable) max-width doesn work properly, new prop to wrap text when use maxWidth fix(VDataTable): max-width doesn work properly, new prop to wrap text when use maxWidth Jan 2, 2024
@websitevirtuoso websitevirtuoso self-assigned this Jan 2, 2024
@MajesticPotatoe MajesticPotatoe added T: bug Functionality that does not work as intended/expected C: VDataTable VDatatable labels Jan 2, 2024
Prop wrap works only in combination with maxWidth
@johnleider johnleider added this to the v3.6.0 (Nebula) milestone Apr 8, 2024
@johnleider johnleider merged commit dd929f5 into vuetifyjs:dev Apr 8, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VDataTable VDatatable T: bug Functionality that does not work as intended/expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants