Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Re-write filtering in table using regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
romanslonov committed May 10, 2019
1 parent 986113f commit 7dcb0f8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/Table/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
</template>

<script>
import fuzzysearch from 'fuzzysearch';
import VSpinner from '../Spinner';
import { toString } from '../../helpers/util';
Expand Down Expand Up @@ -157,11 +156,22 @@ export default {
mutableItems() {
let items = this.items.slice();
/* Filtering */
if (this.query) {
this.clearSelection();
items = items.filter(item => fuzzysearch(this.query, toString(item)));
let regex;
if (this.query instanceof RegExp) {
regex = this.query;
} else {
regex = new RegExp(`.*${this.query}.*`, 'ig');
}
items = items.filter((item) => {
const test = regex.test(toString(item));
regex.lastIndex = 0;
return test;
});
}
/* Sorting */
const sortCompare = this.sortCompare || defaultSortCompare;
if (this.sortBy) {
items = items.sort((a, b) => {
Expand All @@ -170,6 +180,7 @@ export default {
});
}
/* Paginating */
if (this.perPage) {
items = items.slice((this.currentPage - 1) * this.perPage, this.currentPage * this.perPage);
}
Expand Down

0 comments on commit 7dcb0f8

Please sign in to comment.