Vue-tables-2: Maintain Pagination When Clicking Back From Link

Created on 22 Aug 2019  路  3Comments  路  Source: matfish2/vue-tables-2

  • Vue.js version: 2.6.10
  • consumed using: Webpack via Laravel Mix

How do I preserve the pagination state when I click a link on the table to a new view then click back in the browser? Vue Tables 2 always goes back to page 1 when I click back.

I have Vue.use(ServerTable, {preserveState: true}) set when init the plugin and I am using Vue Router with history set to true.

bug wontfix

Most helpful comment

Okay so I ended up doing the following to work successfully with Laravel pagination and Vue-Tables-2.

created () {
            var url = new URL(window.location.href)
            var pageNumber = url.searchParams.get("page")
            if(!!pageNumber) {
                this.options = {...this.options, initialPage: pageNumber}
            }
}

and then

methods: {
           paginationChanged() {
                console.log("Pagination did change...")
                var url = new URL(window.location.href)
                url.searchParams.set("page", this.$refs.quotesTable.Page)
                window.history.replaceState({}, null, url.href)
                this.options = {...this.options, initialPage: this.$refs.quotesTable.Page}
            },
        }
}
data () {
const vm = this

            return {
                        columns: [],
                        options: {}
            }
}

and the top of the server template

<v-server-table ref="quotesTable" :columns="columns" :options="options" @pagination="paginationChanged">

Hope this helps anyone else using Laravel and this plugin.

All 3 comments

Okay so I ended up doing the following to work successfully with Laravel pagination and Vue-Tables-2.

created () {
            var url = new URL(window.location.href)
            var pageNumber = url.searchParams.get("page")
            if(!!pageNumber) {
                this.options = {...this.options, initialPage: pageNumber}
            }
}

and then

methods: {
           paginationChanged() {
                console.log("Pagination did change...")
                var url = new URL(window.location.href)
                url.searchParams.set("page", this.$refs.quotesTable.Page)
                window.history.replaceState({}, null, url.href)
                this.options = {...this.options, initialPage: this.$refs.quotesTable.Page}
            },
        }
}
data () {
const vm = this

            return {
                        columns: [],
                        options: {}
            }
}

and the top of the server template

<v-server-table ref="quotesTable" :columns="columns" :options="options" @pagination="paginationChanged">

Hope this helps anyone else using Laravel and this plugin.

Pagination should be preserved when using preserveState: true, I will look into it

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JKHeadley picture JKHeadley  路  4Comments

dhdmstjs picture dhdmstjs  路  6Comments

vesper8 picture vesper8  路  6Comments

jigarzon picture jigarzon  路  3Comments

molerat619 picture molerat619  路  4Comments