Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor current pagination solution using router #350

Closed
Viterbo opened this issue Feb 2, 2023 · 0 comments · Fixed by #351
Closed

refactor current pagination solution using router #350

Viterbo opened this issue Feb 2, 2023 · 0 comments · Fixed by #351
Assignees

Comments

@Viterbo
Copy link
Collaborator

Viterbo commented Feb 2, 2023

          @EJSG, thanks for that review! That bug you found was the last drop I needed to push myself to find a better solution. Fortunately, I did.

I changed the strategy from a homemade solution using history.pushState to a more easy and elegant solution using $router (which is intended for these cases).

    async onPaginationChange(props) {
        const { page, rowsPerPage } = props.pagination;
        this.$router.push({
            hash: window.location.hash,
            query: {
                ...this.$route.query,
                page: `${page},${rowsPerPage}`,
            },
        });
    },
watch: {
    '$route.query.page': {
        handler(_pag) {
            let pag = _pag;
            let page = 1;
            let size = this.pagination.rowsPerPage;

            // we also allow to pass a single number as the page number
            if (typeof pag === 'number') {
                page = pag;
            } else if (typeof pag === 'string') {
                // we also allow to pass a string of two numbers: [page, rowsPerPage]
                const [p, s] = pag.split(',');
                page = p;
                size = s;
            }

            this.setPagination(page, size);
        },
        immediate: true,
    },
},

I'm going to create a new issue to implement this same solution on the TransactionTable

Originally posted by @Viterbo in #346 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant