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): fix filter not work #19881

Merged
merged 1 commit into from
May 29, 2024
Merged

Conversation

lzl0304
Copy link
Contributor

@lzl0304 lzl0304 commented May 24, 2024

Description

fixes #19596

Markup:

<template>
  <v-app>
    <v-container>
      <v-data-table
        :custom-filter="filterOnlyCapsText"
        :headers="headers"
        :items="desserts"
        :search="search"
        class="elevation-1"
        item-key="name"
      >
        <template #top>
          <v-text-field
            v-model="search"
            class="mx-4"
            label="Search (UPPER CASE ONLY)"
          />
        </template>
        <template #body.append>
          <tr>
            <td />
            <td>
              <v-text-field
                v-model="calories"
                label="Less than"
                type="number"
              />
            </td>
            <td colspan="4" />
          </tr>
        </template>
      </v-data-table>
    </v-container>
  </v-app>
</template>

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

  const search = ref('')
  const calories = ref('')

  const desserts = ref([
    {
      name: 'Frozen Yogurt',
      calories: 159,
    },
    {
      name: 'Ice cream sandwich',
      calories: 237,
    },
    {
      name: 'Eclair',
      calories: 262,
    },
    {
      name: 'Cupcake',
      calories: 305,
    },
    {
      name: 'Gingerbread',
      calories: 356,
    },
  ])

  const headers = computed(() => [
    {
      text: 'Dessert (100g serving)',
      align: 'start',
      sortable: false,
      value: 'name',
    },
    {
      text: 'Calories',
      value: 'calories',
      filter: value => {
        if (!calories.value) return true

        return value < parseInt(calories.value)
      },
    },
  ])

  const filterOnlyCapsText = (value, search, item) => {
    return (
      value != null &&
      search != null &&
      typeof value === 'string' &&
      value.toString().toLocaleUpperCase().indexOf(search) !== -1
    )
  }
</script>

@MajesticPotatoe MajesticPotatoe added T: bug Functionality that does not work as intended/expected C: VDataTable VDatatable labels May 27, 2024
@johnleider johnleider added this to the v3.6.x milestone May 29, 2024
@johnleider johnleider merged commit b3eafb2 into vuetifyjs:master May 29, 2024
10 checks passed
@lzl0304 lzl0304 deleted the fix-19596 branch June 26, 2024 23:13
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.5.15] v-data-table headers filter do not work
3 participants