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

Adding Buttons in dropdown like Select All, Deselect All. #172

Closed
umang-gramener opened this issue Dec 6, 2021 · 4 comments
Closed

Adding Buttons in dropdown like Select All, Deselect All. #172

umang-gramener opened this issue Dec 6, 2021 · 4 comments

Comments

@umang-gramener
Copy link

I tried achieving this with beforelist, but was not able to make the button reactive, i even tried putting as check boxes still nothing worked.
is there a way we can implement this? or can we get it built in as options?

@adamberecz
Copy link
Collaborator

This should be it:

<template>
  <div id="app">
    <div>
      <Multiselect
        v-model="value"
        :options="options"
        mode="multiple"
        ref="select$"
      >
        <template #beforelist>
          <a href="" @click.prevent="handleSelectAll">Select all</a> • 
          <a href="" @click.prevent="handleDeselectAll">Deselect all</a>
        </template>
      </Multiselect>
    </div>
  </div>
</template>

<script>
import Multiselect from '@vueform/multiselect'

export default {
  name: 'App',
  components: {
    Multiselect,
  },
  data() {
    return {
      value: [],
      options: ['value1', 'value2', 'value3'],
      select$: null,
    }
  },
  methods: {
    handleSelectAll() {
      this.select$.selectAll()
    },
    handleDeselectAll() {
      this.select$.clear()
    },
  },
  mounted() {
    this.select$ = this.$refs.select$
  }
}
</script>

The selectAll method will be available in next release, until that you can use:

handleSelectAll() {
  this.select$.select(this.select$.filteredOptions)
}

@ponochovny
Copy link

For some reason when I click many times this "Select all" button - it doubles 'internalValue', and the length of values doubles, so even the message 'multipleLabelText' increases with the count of values

@ponochovny
Copy link

Found the solution. When click 'Select all' just execute 'Deselect all' and 'Select all' methods

@georginklv
Copy link

This how it's suppose to happen with composition api ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants