Skip to content

Commit 25da7c0

Browse files
authored
components.md add server-side pagination example
1 parent c17d174 commit 25da7c0

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/components.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,65 @@ export default {
315315
</script>
316316
```
317317

318+
### server-side pagination
319+
320+
When you want to use server-side pagination you need to pass the ids from the server to vuex. It can be done by a combination of `query`, `fetchQuery` and `editScope` as described below. The `fetchQuery`-prop is only computed after items from the server arrived. The ids for the `find` getter as well as the total amount of available values `total` are extracted by the `edit-scope` function and stored in `data`:
321+
322+
```html
323+
<template>
324+
<FeathersVuexFind
325+
:service="service"
326+
:query="internalQuery"
327+
:fetch-query="fetchQuery"
328+
:edit-scope="getPaginationInfo"
329+
>
330+
<div slot-scope="{ items: todos }">
331+
{{todos}}
332+
</div>
333+
</FeathersVuexFind>
334+
</template>
335+
336+
<script>
337+
export default {
338+
data() {
339+
return {
340+
service: 'users',
341+
ids: [],
342+
query: {
343+
isComplete: true
344+
},
345+
total: 0,
346+
limit: 10,
347+
skip: 0
348+
};
349+
},
350+
computed: {
351+
internalQuery() {
352+
const { idField } = this.$store.state[this.service];
353+
return {
354+
[idField]: {
355+
$in: this.ids
356+
}
357+
};
358+
},
359+
fetchQuery() {
360+
return Object.assign({}, this.query, { $limit: this.limit, $skip: this.skip });
361+
}
362+
},
363+
methods: {
364+
getPaginationInfo (scope) {
365+
const { queryInfo, pageInfo } = scope;
366+
367+
this.total = queryInfo.total;
368+
if (pageInfo && pageInfo.ids) {
369+
this.ids = pageInfo.ids;
370+
}
371+
}
372+
}
373+
}
374+
</script>
375+
```
376+
318377
### Query when certain conditions are met
319378

320379
Sometimes you only want to query the API server when certain conditions are met. This example shows how to query the API server when the `userSearch` has as least three characters. This property does not affect the internal `find` getter, so the `items` will still update when the `userSearch` property has fewer than three characters, just no API request will be made. The `isFindPending` attribute is used to indicate when data is being loaded from the server.

0 commit comments

Comments
 (0)