Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
</FilterableTable>
<Pagination
ref="paginator"
:key="dataPagination.page"
:class="{
'tw-opacity-50':showPlaceholder,
'tw-pt-3':true
}"
:total="dataPagination.total"
:page="dataPagination.page"
:pages="dataPagination.pages"
:per-page="dataPagination.perPage"
@perPage="onPerPage"
@go="onGo" />
</div>
Expand Down Expand Up @@ -112,6 +112,7 @@ const hookData = async () => {

const onPerPage = async (perPage) => {
dataPagination.value.perPage = perPage;
dataPagination.value.page = 1;
await hookData();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
:total="dataPagination.total"
:page="dataPagination.page"
:pages="dataPagination.pages"
:per-page="dataPagination.perPage"
@perPage="onPerPage"
@go="onGo" />
</div>
Expand Down Expand Up @@ -122,6 +123,7 @@ const onGo = async (page) => {

const onPerPage = async (perPage) => {
dataPagination.value.perPage = perPage;
dataPagination.value.page = 1;

await hookGetData();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
:total="dataPagination.total"
:page="dataPagination.page"
:pages="dataPagination.pages"
:per-page="dataPagination.perPage"
@perPage="onPerPage"
@go="onGo" />
</div>
Expand Down Expand Up @@ -95,6 +96,7 @@ const onGo = async (page) => {

const onPerPage = async (perPage) => {
dataPagination.value.perPage = perPage;
dataPagination.value.page = 1;

await hookGetData();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
:total="dataPagination.total"
:page="dataPagination.page"
:pages="dataPagination.pages"
:per-page="dataPagination.perPage"
@perPage="onPerPage"
@go="onGo" />
</div>
Expand Down Expand Up @@ -97,6 +98,7 @@ const onGo = async (page) => {

const onPerPage = async (perPage) => {
dataPagination.value.perPage = perPage;
dataPagination.value.page = 1;

await hookGetData();
};
Expand Down
3 changes: 2 additions & 1 deletion resources/jscomposition/cases/casesMain/CasesDataSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
</FilterableTable>
<Pagination
ref="paginator"
:key="dataPagination.page"
:class="{
'tw-opacity-50':showPlaceholder,
'tw-pt-3':true
}"
:total="dataPagination.total"
:page="dataPagination.page"
:pages="dataPagination.pages"
:per-page="dataPagination.perPage"
@perPage="onPerPage"
@go="onGo" />
</div>
Expand Down Expand Up @@ -145,6 +145,7 @@ const onGo = async (page) => {

const onPerPage = async (perPage) => {
dataPagination.value.perPage = perPage;
dataPagination.value.page = 1;

await hookGetData();
};
Expand Down
36 changes: 30 additions & 6 deletions resources/jscomposition/system/table/Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
</div>
</template>
<script setup>
import { ref, computed } from "vue";
import { ref, computed, watch } from "vue";
import { t } from "i18next";
import { Dropdown } from "../../base/form";

Expand All @@ -144,6 +144,10 @@ const props = defineProps({
type: Number,
default: () => (0),
},
perPage: {
type: Number,
default: () => (15),
},
options: {
type: Array,
default: () => [],
Expand All @@ -159,7 +163,7 @@ const totalModelLabel = computed(() => {
return `${t("{{count}} Items", { count: props.total })}`;
});

const pageModel = ref(props.page);
const pageModel = ref(props.page || 1);
const optionsPerPage = [
{
value: 15,
Expand All @@ -177,10 +181,12 @@ const optionsPerPage = [

const optionsModel = ref(props.options.length ? props.options : optionsPerPage);

const selectedOption = ref({
value: 15,
label: "15 items",
});
const resolveOption = (value) => {
const matched = optionsModel.value.find((option) => option.value === value);
return matched || { value, label: `${value} ${t("Per page")}` };
};

const selectedOption = ref(resolveOption(props.perPage || 15));

const first = () => {
if (pageModel.value > 1) {
Expand Down Expand Up @@ -226,6 +232,24 @@ const setPerPage = (value) => {
defineExpose({
setPerPage,
});

watch(
() => props.page,
(value) => {
if (value && value !== pageModel.value) {
pageModel.value = value;
}
}
);

watch(
() => props.perPage,
(value) => {
if (value && value !== selectedOption.value?.value) {
selectedOption.value = resolveOption(value);
}
}
);
</script>
<style scoped>
/* Chrome, Safari, Edge, Opera */
Expand Down
Loading