简体   繁体   English

如何以编程方式更改 PrimeVue Paginator 组件上的当前页面?

[英]How to programmatically change current page on PrimeVue Paginator component?

Can I set a current-page props on PrimeVue Paginator?我可以在 PrimeVue Paginator 上设置当前页面属性吗?

https://primefaces.org/primevue/paginator https://primefaces.org/primevue/paginator

I want to detect a query string to set current page我想检测一个查询字符串来设置当前页面

seems there is no props I can set?好像没有我可以设置的道具?

I tried :value , :current , :current-page我试过:value , :current , :current-page

no one is working, always on page 1.没有人在工作,总是在第一页。

在此处输入图像描述

You can use first to retrieve and or modify the current position.您可以使用first来检索或修改当前的 position。 If you have one row per page :row="1" , first equals page - 1 .如果每页有一行:row="1" ,则first等于page - 1

<Paginator
    v-model:first="first"
    :rows="1"
    :total-records="10"
    />
<Button @click="first = 0">Go to page 1</Button>
<Button @click="first = 2">Go to page 3</Button>

If you are displaying more than one row per page, eg :row="10" you have to some math;-) Basically: first = (page - 1) * rows如果您每页显示多行,例如:row="10"您必须进行一些数学运算;-) 基本上: first = (page - 1) * rows

<Paginator
    v-model:first="first"
    :rows="10"
    :total-records="100"
    />
<Button @click="first = 0">Go to page 1</Button>
<Button @click="first = 20">Go to page 3</Button>

Just realized that you need to actually tell the Paginator how much you want to skip, not the math to calculate the current page .刚刚意识到你需要实际告诉Paginator你想跳过多少,而不是计算current page的数学。

<Paginator
    :rows="movieStore.movieLimitCount"
    @page="onPaginate"
    :totalRecords="movieStore.movieCount"
    class="mt-5"
    :alwaysShow="false"
    v-model:first="offset"
  />

<script setup>
const offset = ref(0);
const onPaginate = (e) => offset.value = e.rows * e.page;
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM