mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-16 09:10:33 +03:00
Merge branch 'feature/custom-filter'
# Conflicts: # dev.html # yarn.lock
This commit is contained in:
+42
-22
@@ -525,21 +525,6 @@
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback to filter the search result the label text.
|
||||
* @type {Function}
|
||||
* @param {Object || String} option
|
||||
* @param {String} label
|
||||
* @param {String} search
|
||||
* @return {Boolean}
|
||||
*/
|
||||
filterFunction: {
|
||||
type: Function,
|
||||
default(option, label, search) {
|
||||
return (label || '').toLowerCase().indexOf(search.toLowerCase()) > -1
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* An optional callback function that is called each time the selected
|
||||
* value(s) change. When integrating with Vuex, use this callback to trigger
|
||||
@@ -593,6 +578,47 @@
|
||||
default: true
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback to determine if the provided option should
|
||||
* match the current search text. Used to determine
|
||||
* if the option should be displayed.
|
||||
* @type {Function}
|
||||
* @param {Object || String} option
|
||||
* @param {String} label
|
||||
* @param {String} search
|
||||
* @return {Boolean}
|
||||
*/
|
||||
filterBy: {
|
||||
type: Function,
|
||||
default(option, label, search) {
|
||||
return (label || '').toLowerCase().indexOf(search.toLowerCase()) > -1
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback to filter results when search text
|
||||
* is provided. Default implementation loops
|
||||
* each option, and returns the result of
|
||||
* this.filterBy.
|
||||
* @type {Function}
|
||||
* @param {Array} list of options
|
||||
* @param {String} search text
|
||||
* @param {Object} vSelect instance
|
||||
* @return {Boolean}
|
||||
*/
|
||||
filter: {
|
||||
"type": Function,
|
||||
default(options, search) {
|
||||
return options.filter((option) => {
|
||||
let label = this.getOptionLabel(option)
|
||||
if (typeof label === 'number') {
|
||||
label = label.toString()
|
||||
}
|
||||
return this.filterBy(option, label, search)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* User defined function for adding Options
|
||||
* @type {Function}
|
||||
@@ -988,13 +1014,7 @@
|
||||
if (!this.filterable && !this.taggable) {
|
||||
return this.mutableOptions.slice()
|
||||
}
|
||||
let options = this.mutableOptions.filter((option) => {
|
||||
let label = this.getOptionLabel(option)
|
||||
if (typeof label === 'number') {
|
||||
label = label.toString()
|
||||
}
|
||||
return this.filterFunction(option, label, this.search)
|
||||
})
|
||||
let options = this.search.length ? this.filter(this.mutableOptions, this.search, this) : this.mutableOptions;
|
||||
if (this.taggable && this.search.length && !this.optionExists(this.search)) {
|
||||
options.unshift(this.search)
|
||||
}
|
||||
|
||||
+15
-7
@@ -1,8 +1,10 @@
|
||||
import Vue from 'vue'
|
||||
import vSelect from './components/Select.vue'
|
||||
import countries from 'docs/data/advanced.js'
|
||||
import Fuse from 'fuse.js'
|
||||
import debounce from 'lodash/debounce'
|
||||
import resource from 'vue-resource'
|
||||
import vSelect from './components/Select.vue'
|
||||
import countries from 'docs/data/advanced.js'
|
||||
import fuseSearchOptions from './fuseSearchOptions'
|
||||
|
||||
Vue.use(resource)
|
||||
|
||||
@@ -18,11 +20,12 @@ new Vue({
|
||||
value: null,
|
||||
options: countries,
|
||||
ajaxRes: [],
|
||||
people: []
|
||||
people: [],
|
||||
fuseSearchOptions
|
||||
},
|
||||
methods: {
|
||||
search(search, loading) {
|
||||
loading(true)
|
||||
loading(true);
|
||||
this.getRepositories(search, loading, this)
|
||||
},
|
||||
searchPeople(search, loading) {
|
||||
@@ -37,9 +40,14 @@ new Vue({
|
||||
}, 250),
|
||||
getRepositories: debounce((search, loading, vm) => {
|
||||
vm.$http.get(`https://api.github.com/search/repositories?q=${search}`).then(res => {
|
||||
vm.ajaxRes = res.data.items
|
||||
vm.ajaxRes = res.data.items;
|
||||
loading(false)
|
||||
})
|
||||
}, 250)
|
||||
}, 250),
|
||||
fuseSearch(options, search) {
|
||||
return new Fuse(options, {
|
||||
keys: ['title', 'author.firstName', 'author.lastName'],
|
||||
}).search(search);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,163 @@
|
||||
export default [
|
||||
{
|
||||
title: "Old Man's War",
|
||||
author: {
|
||||
firstName: "John",
|
||||
lastName: "Scalzi"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "The Lock Artist",
|
||||
author: {
|
||||
firstName: "Steve",
|
||||
lastName: "Hamilton"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "HTML5",
|
||||
author: {
|
||||
firstName: "Remy",
|
||||
lastName: "Sharp"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Right Ho Jeeves",
|
||||
author: {
|
||||
firstName: "P.D",
|
||||
lastName: "Woodhouse"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "The Code of the Wooster",
|
||||
author: {
|
||||
firstName: "P.D",
|
||||
lastName: "Woodhouse"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Thank You Jeeves",
|
||||
author: {
|
||||
firstName: "P.D",
|
||||
lastName: "Woodhouse"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "The DaVinci Code",
|
||||
author: {
|
||||
firstName: "Dan",
|
||||
lastName: "Brown"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Angels & Demons",
|
||||
author: {
|
||||
firstName: "Dan",
|
||||
lastName: "Brown"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "The Silmarillion",
|
||||
author: {
|
||||
firstName: "J.R.R",
|
||||
lastName: "Tolkien"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Syrup",
|
||||
author: {
|
||||
firstName: "Max",
|
||||
lastName: "Barry"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "The Lost Symbol",
|
||||
author: {
|
||||
firstName: "Dan",
|
||||
lastName: "Brown"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "The Book of Lies",
|
||||
author: {
|
||||
firstName: "Brad",
|
||||
lastName: "Meltzer"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Lamb",
|
||||
author: {
|
||||
firstName: "Christopher",
|
||||
lastName: "Moore"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Fool",
|
||||
author: {
|
||||
firstName: "Christopher",
|
||||
lastName: "Moore"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Incompetence",
|
||||
author: {
|
||||
firstName: "Rob",
|
||||
lastName: "Grant"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Fat",
|
||||
author: {
|
||||
firstName: "Rob",
|
||||
lastName: "Grant"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Colony",
|
||||
author: {
|
||||
firstName: "Rob",
|
||||
lastName: "Grant"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Backwards, Red Dwarf",
|
||||
author: {
|
||||
firstName: "Rob",
|
||||
lastName: "Grant"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "The Grand Design",
|
||||
author: {
|
||||
firstName: "Stephen",
|
||||
lastName: "Hawking"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "The Book of Samson",
|
||||
author: {
|
||||
firstName: "David",
|
||||
lastName: "Maine"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "The Preservationist",
|
||||
author: {
|
||||
firstName: "David",
|
||||
lastName: "Maine"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Fallen",
|
||||
author: {
|
||||
firstName: "David",
|
||||
lastName: "Maine"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Monster 1959",
|
||||
author: {
|
||||
firstName: "David",
|
||||
lastName: "Maine"
|
||||
}
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user