1. <legend id='apGjH'><style id='apGjH'><dir id='apGjH'><q id='apGjH'></q></dir></style></legend>
    2. <i id='apGjH'><tr id='apGjH'><dt id='apGjH'><q id='apGjH'><span id='apGjH'><b id='apGjH'><form id='apGjH'><ins id='apGjH'></ins><ul id='apGjH'></ul><sub id='apGjH'></sub></form><legend id='apGjH'></legend><bdo id='apGjH'><pre id='apGjH'><center id='apGjH'></center></pre></bdo></b><th id='apGjH'></th></span></q></dt></tr></i><div id='apGjH'><tfoot id='apGjH'></tfoot><dl id='apGjH'><fieldset id='apGjH'></fieldset></dl></div>
        <bdo id='apGjH'></bdo><ul id='apGjH'></ul>
    3. <tfoot id='apGjH'></tfoot>

        <small id='apGjH'></small><noframes id='apGjH'>

      1. 如何使用“自定义过滤器"?vuetify中数据表中的道具?或如何创建自定义过滤器以按标题过滤?

        时间:2023-09-05
          <tbody id='wunY7'></tbody>
      2. <i id='wunY7'><tr id='wunY7'><dt id='wunY7'><q id='wunY7'><span id='wunY7'><b id='wunY7'><form id='wunY7'><ins id='wunY7'></ins><ul id='wunY7'></ul><sub id='wunY7'></sub></form><legend id='wunY7'></legend><bdo id='wunY7'><pre id='wunY7'><center id='wunY7'></center></pre></bdo></b><th id='wunY7'></th></span></q></dt></tr></i><div id='wunY7'><tfoot id='wunY7'></tfoot><dl id='wunY7'><fieldset id='wunY7'></fieldset></dl></div>

          <small id='wunY7'></small><noframes id='wunY7'>

            <legend id='wunY7'><style id='wunY7'><dir id='wunY7'><q id='wunY7'></q></dir></style></legend>

              • <bdo id='wunY7'></bdo><ul id='wunY7'></ul>

              • <tfoot id='wunY7'></tfoot>

                  本文介绍了如何使用“自定义过滤器"?vuetify中数据表中的道具?或如何创建自定义过滤器以按标题过滤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  截至发稿之日,我找不到在数据表中使用自定义过滤器"道具的任何文档.

                  我只想创建一个自定义过滤器来按标题过滤我的数据表.我有一个下拉列表,当用户单击下拉列表的选项之一时,它会过滤列表中的一个特定标题.

                  示例:下拉选项:食物类型:水果、肉类、蔬菜

                  1. Bakchoi(蔬菜)
                  2. 猪肉(肉)
                  3. 鸡大腿(肉)
                  4. 西瓜(水果)

                  如果我选择下拉菜单作为肉,它应该只显示猪肉和鸡腿.

                  解决方案

                  看Github上的代码1,貌似是用customFilter prop覆盖用于确定 filter 属性如何应用于表中的项目的默认方法.

                  默认的 customFilter 方法将 filter 函数应用于每个项目对象的每个属性名称,并过滤掉任何不包含通过过滤器的属性名称的项目:

                  <块引用>

                  customFilter: {类型:函数,默认值:(项目、搜索、过滤器)=>{搜索 = search.toString().toLowerCase()return items.filter(i => (Object.keys(i).some(j => filter(i[j], search))))}},

                  如果您想阻止任何列包含在过滤器中,或者如果您一直希望阻止过滤掉特定行,则可能需要覆盖此函数.

                  您会注意到该方法还依赖于 search 属性,它必须是一个字符串.

                  <小时>

                  说了这么多,你真的不需要使用那个道具来做你想做的事.您应该只创建一个计算属性来根据您的下拉值过滤项目,并将该计算属性作为 items 属性传递.

                  这是一个例子:

                  new Vue({埃尔:'#app',数据() {返回 {食物: [{名称:'Bakchoi',类型:'蔬菜',卡路里:100},{名称:'猪肉',类型:'肉',卡路里:200},{名称:'鸡大腿',类型:'肉',卡路里:300},{名称:'西瓜',类型:'水果',卡路里:10},],标题:[{ 文本:名称",对齐:左",值:名称"},{ text: '食物类型', align: 'left', value: 'type' },{ 文本:卡路里",对齐:左",值:卡路里"},],食物类型:空,};},计算:{过滤项目(){返回 this.food.filter((i) => {返回 !this.foodType ||(i.type === this.foodType);})}}})

                  <script src="https://unpkg.com/vue@2.4.2/dist/vue.js"></脚本><script src="https://unpkg.com/vuetify@0.15.2/dist/vuetify.js"></script><link rel="stylesheet" href="https://unpkg.com/vuetify@0.15.2/dist/vuetify.min.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|材料+图标"><div id="app"><v-app>

                  <小时>

                  1. 这个答案是在 Vuetify 在 v0.15.2 时编写的.VDataTable的源代码可以在此处找到该版本的组件.

                  As of date of posting, I cannot find any documentation to use the "custom filter" prop in data tables.

                  I just want to create a custom filter to filter my data table by headers. I have a dropdown, and when user click on one of the options for the dropdown, it will filter the list for one specific header.

                  Example: Dropdown options: Food type: fruit, meat, vegetable

                  1. Bakchoi (vegetable)
                  2. Pork (meat)
                  3. Chicken Thigh (meat)
                  4. watermelon (fruit)

                  If I select dropdown as meat, it should only show me pork and chicken thigh.

                  解决方案

                  Looking at the code on Github1, it looks like the customFilter prop is used to overwrite the default method used to determine how the filter prop is applied to the items in the table.

                  The default customFilter method applies the filter function to each property name of each item object and filters out any items that don't include one property name that passes the filter:

                  customFilter: {
                    type: Function,
                    default: (items, search, filter) => {
                      search = search.toString().toLowerCase()
                      return items.filter(i => (
                        Object.keys(i).some(j => filter(i[j], search))
                      ))
                    }
                  },
                  

                  You might want to overwrite this function if you wanted to prevent any columns from being included in the filter or if there were specific rows that you always wanted to prevent from being filtered out.

                  You'll notice that the method also depends on the search prop, which must be a string.


                  All that said, you really don't need to use that prop for what you want to do. You should just make a computed property to filter the items based on your dropdown value and pass that computed property as the items prop.

                  Here's an example:

                  new Vue({
                    el: '#app',
                    data() {
                      return {
                        food: [
                          { name: 'Bakchoi', type: 'vegetable', calories: 100 },
                          { name: 'Pork', type: 'meat', calories: 200 },
                          { name: 'Chicken Thigh', type: 'meat', calories: 300 },
                          { name: 'Watermelon', type: 'fruit', calories: 10 },
                        ],
                        headers: [
                          { text: 'Name', align: 'left', value: 'name' },
                          { text: 'Food Type', align: 'left', value: 'type' }, 
                          { text: 'Calories', align: 'left', value: 'calories' },
                        ],
                        foodType: null,
                      };
                    },
                    computed: {
                      filteredItems() {
                        return this.food.filter((i) => {
                          return !this.foodType || (i.type === this.foodType);
                        })
                      }
                    }
                  })

                  <script src="https://unpkg.com/vue@2.4.2/dist/vue.js"></script>
                  <script src="https://unpkg.com/vuetify@0.15.2/dist/vuetify.js"></script>
                  <link rel="stylesheet" href="https://unpkg.com/vuetify@0.15.2/dist/vuetify.min.css">
                  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons">
                  
                  <div id="app">
                    <v-app>  
                      <v-select 
                        label="Food Type" 
                        :items="['vegetable', 'meat', 'fruit']"
                        v-model="foodType"
                      ></v-select>
                      
                      <v-data-table 
                        :headers="headers"
                        :items="filteredItems"
                        hide-actions
                      >
                        <template slot="items" scope="{ item }">
                          <td>{{ item.name }}</td>
                          <td>{{ item.type }}</td>
                          <td>{{ item.calories }}</td>
                        </template>
                      </v-data-table>
                    </v-app>
                  </div>


                  1. This answer was written when Vuetify was at v0.15.2. The source code for the VDataTable component at that version can be found here.

                  这篇关于如何使用“自定义过滤器"?vuetify中数据表中的道具?或如何创建自定义过滤器以按标题过滤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  • <legend id='55AZv'><style id='55AZv'><dir id='55AZv'><q id='55AZv'></q></dir></style></legend><tfoot id='55AZv'></tfoot>

                    <small id='55AZv'></small><noframes id='55AZv'>

                        <tbody id='55AZv'></tbody>

                        <bdo id='55AZv'></bdo><ul id='55AZv'></ul>

                        1. <i id='55AZv'><tr id='55AZv'><dt id='55AZv'><q id='55AZv'><span id='55AZv'><b id='55AZv'><form id='55AZv'><ins id='55AZv'></ins><ul id='55AZv'></ul><sub id='55AZv'></sub></form><legend id='55AZv'></legend><bdo id='55AZv'><pre id='55AZv'><center id='55AZv'></center></pre></bdo></b><th id='55AZv'></th></span></q></dt></tr></i><div id='55AZv'><tfoot id='55AZv'></tfoot><dl id='55AZv'><fieldset id='55AZv'></fieldset></dl></div>