options.mjs 881 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Utilities
  2. import { computed, watch } from 'vue';
  3. import { deepEqual, getCurrentInstance } from "../../../util/index.mjs"; // Types
  4. export function useOptions(_ref) {
  5. let {
  6. page,
  7. itemsPerPage,
  8. sortBy,
  9. groupBy,
  10. search
  11. } = _ref;
  12. const vm = getCurrentInstance('VDataTable');
  13. const options = computed(() => ({
  14. page: page.value,
  15. itemsPerPage: itemsPerPage.value,
  16. sortBy: sortBy.value,
  17. groupBy: groupBy.value,
  18. search: search.value
  19. }));
  20. let oldOptions = null;
  21. watch(options, () => {
  22. if (deepEqual(oldOptions, options.value)) return;
  23. // Reset page when searching
  24. if (oldOptions && oldOptions.search !== options.value.search) {
  25. page.value = 1;
  26. }
  27. vm.emit('update:options', options.value);
  28. oldOptions = options.value;
  29. }, {
  30. deep: true,
  31. immediate: true
  32. });
  33. }
  34. //# sourceMappingURL=options.mjs.map