vuestic-ui
Version:
Vue 3 UI Framework
30 lines (29 loc) • 999 B
JavaScript
import { computed } from "vue";
import { u as useCurrentPageProp } from "./useCommonProps.js";
import { u as useThrottleProps, a as useThrottleValue } from "../../../composables/useThrottle.js";
const usePaginatedRowsProps = {
...useThrottleProps,
...useCurrentPageProp,
perPage: { type: Number }
};
const usePaginatedRows = (sortedRows, props) => {
const paginatedRows = computed(() => {
if (!props.perPage || props.perPage < 0) {
return sortedRows.value;
}
if (!props.currentPage || props.currentPage < 0) {
return sortedRows.value.slice(0, props.perPage);
}
const pageStartIndex = props.perPage * (props.currentPage - 1);
return sortedRows.value.slice(pageStartIndex, pageStartIndex + props.perPage);
});
const paginatedRowsThrottled = useThrottleValue(paginatedRows, props);
return {
paginatedRows: paginatedRowsThrottled
};
};
export {
usePaginatedRows as a,
usePaginatedRowsProps as u
};
//# sourceMappingURL=usePaginatedRows.js.map