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(VDataTableFooter): dont apply i18n to numbers #18980

Merged
merged 2 commits into from
Mar 30, 2024

Conversation

websitevirtuoso
Copy link
Contributor

I couldn't create reproduction link in playground.
Use this vuetify configuration on local machine

import '@mdi/font/css/materialdesignicons.css'
import 'vuetify/src/styles/main.sass'

import { createVuetify } from 'vuetify/src/framework'
import * as directives from 'vuetify/src/directives'
// import { createVueI18nAdapter } from 'vuetify/locale/adapters/vue-i18n'
import { createVueI18nAdapter } from 'vuetify/src/locale/adapters/vue-i18n'
import { createI18n, useI18n } from 'vue-i18n'
import { en, sv } from 'vuetify/src/locale'

import date from './vuetify/date'
import defaults from './vuetify/defaults'
import icons from './vuetify/icons'
// import locale from './vuetify/locale'

const messages = {
  en: {
    $vuetify: {
      ...en,
      dataIterator: {
        rowsPerPageText: "Items per page:",
        // pageText: "{0}-{1} of {2}",
      },
    },
  },
  sv: {
    $vuetify: {
      ...sv,
      dataIterator: {
        rowsPerPageText: "Element per sida:",
        // pageText: "{0}-{1} av {2}",
      },
    },
  },
}

const i18n = createI18n({
  legacy: false, // Vuetify does not support the legacy mode of vue-i18n
  locale: "sv",
  fallbackLocale: "en",
  messages,
})

export default createVuetify({
  directives,
  ssr: !!process.env.VITE_SSR,
  date,
  defaults,
  icons,
  theme: {
    defaultTheme: 'light',
    surface: '#6200EE',
  },
  locale: {
    adapter: createVueI18nAdapter({ i18n, useI18n }),
  },
})

Description

Fixes: #18978

Markup:

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

<script setup>
import { ref } from 'vue'

const cars = [
  {
    name: 'Ford Mustang',
    horsepower: 450,
    fuel: 'Gasoline',
    origin: 'USA',
    price: 55000,
  },
  {
    name: 'Tesla Model S',
    horsepower: 670,
    fuel: 'Electric',
    origin: 'USA',
    price: 79999,
  },
  {
    name: 'BMW M3',
    horsepower: 503,
    fuel: 'Gasoline',
    origin: 'Germany',
    price: 70000,
  },
  {
    name: 'Audi RS6',
    horsepower: 591,
    fuel: 'Gasoline',
    origin: 'Germany',
    price: 109000,
  },
  {
    name: 'Chevrolet Camaro',
    horsepower: 650,
    fuel: 'Gasoline',
    origin: 'USA',
    price: 62000,
  },
  {
    name: 'Porsche 911',
    horsepower: 379,
    fuel: 'Gasoline',
    origin: 'Germany',
    price: 101000,
  },
  {
    name: 'Jaguar F-Type',
    horsepower: 575,
    fuel: 'Gasoline',
    origin: 'UK',
    price: 61000,
  },
  {
    name: 'Mazda MX-5',
    horsepower: 181,
    fuel: 'Gasoline',
    origin: 'Japan',
    price: 26000,
  },
  {
    name: 'Nissan GT-R',
    horsepower: 565,
    fuel: 'Gasoline',
    origin: 'Japan',
    price: 113540,
  },
  {
    name: 'Mercedes-AMG GT',
    horsepower: 523,
    fuel: 'Gasoline',
    origin: 'Germany',
    price: 115900,
  },
]

const FakeAPI = {
  async fetch ({ page, itemsPerPage, sortBy }) {
    return new Promise(resolve => {
      setTimeout(() => {
        const start = (page - 1) * itemsPerPage
        const end = start + itemsPerPage
        const items = cars.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)
    })
  },
}
const itemsPerPage = ref(5)
const headers = ref([
  { title: 'Car Model', key: 'name', align: 'start' },
  { title: 'Horsepower', key: 'horsepower', align: 'end' },
  { title: 'Fuel Type', key: 'fuel', align: 'start' },
  { title: 'Origin', key: 'origin', align: 'start' },
  { title: 'Price ($)', key: 'price', align: 'end' },
])
const serverItems = ref([])
const loading = ref(true)
const totalItems = ref(0)
function loadItems ({ page, itemsPerPage, sortBy }) {
  loading.value = true
  FakeAPI.fetch({ page, itemsPerPage, sortBy }).then(({ items, total }) => {
    serverItems.value = items
    totalItems.value = total
    loading.value = false
  })
}
</script>

@websitevirtuoso websitevirtuoso self-assigned this Jan 5, 2024
@websitevirtuoso websitevirtuoso added T: bug Functionality that does not work as intended/expected C: VDataTable VDatatable labels Jan 5, 2024
@websitevirtuoso websitevirtuoso linked an issue Jan 5, 2024 that may be closed by this pull request
@johnleider johnleider added this to the v3.4.x milestone Jan 8, 2024
johnleider
johnleider previously approved these changes Jan 8, 2024
@johnleider
Copy link
Member

Please update or resolve build issues:

image

@websitevirtuoso
Copy link
Contributor Author

Updated

@johnleider johnleider removed this from the v3.4.x milestone Jan 22, 2024
@tommie
Copy link

tommie commented Mar 29, 2024

This fix would be useful to reduce console clutter. Is there anything blocking this?

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.

[Bug Report][3.4.9] VDataTable i18n page options
3 participants