No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Q-Select filter an array of objects

    CLI
    2
    2
    1447
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Salim Larhrib last edited by

      Hi everybody,
      I have created a Q-Select component which filters array of objects.

      <template>
        <q-select
          class="custom-selection"
          dense options-dense use-input
          v-model="innerValue"
          v-bind="$attrs"
          v-on="$listeners"
          :options="stringOptions"
          filter @filter="HandleFilter"
          hint="Minimum 3 characters to run filter"
        ></q-select>
      </template>
      

      Because of :options is binded to array of objects, I cannot use the quasar example filter. I have tried to do my own but I cannot access to this.$attrs.optionValue. Can somebody tell me how to reach this property or I have to bind it by hand in the props array ???

      <script>
      export default {
        name: 'SelectFilter',
        props: ['value', 'options'],
        data () {
          return {
            stringOptions: null
          }
        },
        computed: {
          innerValue: {
            get () {
              return this.value
            },
            set (value) {
              this.$emit('input', value)
            }
          }
        },
        methods: {
          HandleFilter (val, update, abort) {
            if (val.length < 3) {
              abort()
              return
            }
            update(() => {
              const needle = val.toLowerCase()
              this.stringOptions = this.options.filter(
                v => v[this.$attrs.optionValue].toLowerCase().indexOf(needle) > -1
              )
            })
          }
        }
      }
      

      Thank you.

      metalsadman 1 Reply Last reply Reply Quote 0
      • metalsadman
        metalsadman @Salim Larhrib last edited by

        @salim-larhrib this.$attrs['option-value'].

        1 Reply Last reply Reply Quote 1
        • First post
          Last post