Skip to content

Filter Component

The Filter supports advanced filtering options, infinite scrolling, and dynamic data handling.

Features

  • Multi-select filtering with options.
  • Advanced filter menu with nested filters.
  • Infinite scrolling support.
  • Customizable UI with slots and props.
  • Avatar support for options.

Basic Usage

Selected: []searchValue:
vue
<template>
  <spr-filter v-model="selectedOptions" v-model:search="searchValue" :options="options" label="Search" hasAvatar />
</template>

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

const options = ref([
  { column: '', isSelected: false, text: 'sample 1', value: 'sample1' },
  { column: '', isSelected: false, text: 'sample 2', value: 'sample2' },
  { column: '', isSelected: false, text: 'sample 3', value: 'sample3' },
  { column: '', isSelected: false, text: 'sample 4', value: 'sample4' },
  { column: '', isSelected: false, text: 'sample 5', value: 'sample5' },
]);

const selectedOptions = ref([]);
const searchValue = ref('');
</script>

Filterable

Selected: []searchValue:
vue
<template>
  <spr-filter
    v-model="selectedOptions1"
    v-model:search="searchValue1"
    :options="options1"
    label="Search"
    :filterMenu="filterMenuList1"
    :filterData="filterMenuOptions1"
    filterable
  />
</template>

<script setup>
const options = ref([
  { column: '', isSelected: false, text: 'sample 1', value: 'sample1' },
  { column: '', isSelected: false, text: 'sample 2', value: 'sample2' },
  { column: '', isSelected: false, text: 'sample 3', value: 'sample3' },
  { column: '', isSelected: false, text: 'sample 4', value: 'sample4' },
  { column: '', isSelected: false, text: 'sample 5', value: 'sample5' },
]);

const filterMenuList = ref([
  { count: 0, isFilterVisible: false, columnName: 'Employee Type', field: 'employeeType' },
  { count: 0, isFilterVisible: false, columnName: 'Department', field: 'department' },
  { count: 0, isFilterVisible: false, columnName: 'Location', field: 'location' },
  { count: 0, isFilterVisible: false, columnName: 'Region', field: 'region' },
  { count: 0, isFilterVisible: false, columnName: 'Job Level', field: 'jobLevel' },
]);

const filterMenuOptions = [
  { column: 'location', isSelected: false, text: 'sample 1', value: 'sample1' },
  { column: 'location', isSelected: false, text: 'sample 2', value: 'sample2' },
  { column: 'location', isSelected: false, text: 'sample 3', value: 'sample3' },
  { column: 'location', isSelected: false, text: 'sample 4', value: 'sample4' },
];

const selectedOptions = ref([]);
const searchValue = ref('');
</script>

Deselect

This example demonstrates how to remove selected options from outside the component.

vue
<template>
  <div class="spr-space-y-3">
    <div class="spr-flex spr-gap-2">
      <div v-for="selected in selectedOptions2">
        <spr-button hasIcon size="small" tone="danger" variant="secondary" @click="removeSelected(selected.value)">
          {{ selected.value }}
          <Icon icon="ph:trash" />
        </spr-button>
      </div>
    </div>
    <spr-filter
      v-model="selectedOptions2"
      v-model:search="searchValue2"
      id="search-filter"
      :deselected="deselected"
      :options="options"
      label="Search"
    />
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { Icon } from '@iconify/vue';
import SprButton from '@/components/button/button.vue';

const options = ref([
  { column: '', isSelected: false, text: 'sample 1', value: 'sample1' },
  { column: '', isSelected: false, text: 'sample 2', value: 'sample2' },
  { column: '', isSelected: false, text: 'sample 3', value: 'sample3' },
  { column: '', isSelected: false, text: 'sample 4', value: 'sample4' },
  { column: '', isSelected: false, text: 'sample 5', value: 'sample5' },
]);

const selectedOptions2 = ref([]);
const searchValue2 = ref('');
const deselected = ref('');

const removeSelected = (removeSelected) => {
  deselected.value = removeSelected;
};
</script>

API Reference

NameDescriptionTypeDefault
modelValueThe selected filter values.Array or String[]
optionsThe list of filter options.Array[]
labelLabel for the filter input.String''
placeholderPlaceholder text for the filter input.String''
disabledDisables the filter input.Booleanfalse
filterableEnables the advanced filter menu.Booleanfalse
idUnique identifier for the filter.String''
filterMenuList of advanced filter menu options.Array[]
filterDataData for the advanced filter menu.Array[]
loadingIndicates if the filter is in a loading state.Booleanfalse
fillingIndicates if the filter is in a filling state.Booleanfalse
searchSearch query for the main filter.String''
searchFilterSearch query for the advanced filter menu.String''
widthWidth of the filter component.String'100%'
deselectedValue of the deselected filter option.String''
hasSearchApiEnables external search API integration.Booleanfalse
hasAvatarEnables avatar display for filter options.Booleanfalse

Events

NamePayload TypeDescription
getFilterDataStringTriggered when fetching filter data for a specific column.
update:modelValueArrayUpdates the selected filter values.
update:searchStringUpdates the search query for the main filter.
update:searchFilterStringUpdates the search query for the advanced filter menu.
selectedFilterArrayEmits the selected filter options.
infiniteScrollTriggerBooleanTriggered when infinite scrolling is activated for the main filter.
infiniteScrollFilterTriggerStringTriggered when infinite scrolling is activated for the advanced filter.

Slots

Slot NameDescription
defaultSlot for customizing the filter input.
loadingSlot for displaying a loading state in the advanced filter menu.
emptySlot for displaying an empty state in the advanced filter menu.
loading-stateSlot for displaying a loading state in the main filter.
empty-stateSlot for displaying an empty state in the main filter.

Advanced Features

Infinite Scrolling

The component supports infinite scrolling for both the main filter and the advanced filter menu. Use the infiniteScrollTrigger and infiniteScrollFilterTrigger events to handle data fetching.

Avatar Support

Enable the hasAvatar prop to display avatars for filter options. Provide an avatar property in the options array.

Product Uses

Sprout HR