FilterBar.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <div class="search-wrapper">
  3. <input type="text" class="search" :placeholder="store.searchPlaceholder" v-model.trim="filterText" @input="doFilter">
  4. <select class="filter-perPage" v-model="store.perPage" @change="changePerPage">
  5. <option v-for="(value, title) in this.perPageOptions"
  6. :value="value"
  7. :selected="store.perPage === value">{{ title }}</option>
  8. </select>
  9. </div>
  10. </template>
  11. <script>
  12. import debounce from 'lodash/debounce';
  13. export default {
  14. props: ['store'],
  15. data: () => ({
  16. filterText: '',
  17. searchPlaceholder: 'Filter...',
  18. selected: ''
  19. }),
  20. computed: {
  21. perPageOptions() {
  22. const options = {
  23. '25': 25,
  24. '50': 50,
  25. '100': 100,
  26. '200': 200,
  27. 'All': ''
  28. };
  29. if (!options[this.store.perPage]) {
  30. options[this.store.perPage] = this.store.perPage;
  31. }
  32. return options;
  33. }
  34. },
  35. created() {
  36. this.doFilter = debounce(() => {
  37. this.$events.fire('filter-set', this.filterText);
  38. }, 250, { leading: false });
  39. this.changePerPage = () => {
  40. this.$events.fire('filter-perPage', this.store.perPage);
  41. };
  42. },
  43. methods: {
  44. resetFilter() {
  45. this.filterText = '';
  46. this.$events.fire('filter-reset');
  47. }
  48. }
  49. }
  50. </script>
  51. <style scoped>
  52. .search-wrapper {
  53. display: flex;
  54. }
  55. .search-wrapper select {
  56. margin-bottom: 0;
  57. margin-left: 1rem;
  58. }
  59. </style>