ratiw / vue-table

data table simplify! -- vuetable is a Vue.js component that will automatically request (JSON) data from the server and display them nicely in html table with swappable/extensible pagination component.
MIT License
1.83k stars 302 forks source link

Transform method doesn't get triggered #162

Open ccramiro opened 7 years ago

ccramiro commented 7 years ago

Hi there,

I am using Java as backed, pagination is handled by Spring, so data needs to be transformed to be displayed properly in the table. Following instructions here, I added a transform method to translate the data I receive to the data vuetable understand. As far as I understand, the transform method should be triggered to build the table but nothing happens and I get an error because the pagination-path is not found. The code is as follows:

Playes

new Vue({
  el: '#app',
  data: {
    columns: ['name', 'games', 'minsPlayed' ]
  },
  methods: {
    transform: function(data) {
      console.log("DATA " + JSON.stringify(data));

      var transformed = {}

      transformed.pagination = {
        total: data.totalElements,
        per_page: data.size,
        current_page: data.number,
        last_page: data.totalPages,
        from: data.from,
        to: data.to
      }
      transformed.mydata = []

      for (var i=0; i < data.length; i++) {
        transformed.data.push({
          player.name: data[i].player.name,
          games: data[i].games,
          minsPlayed: data[i].minsPlayed
        })
      }
    }
  }
})

vue.js, resource and vue-table are added from CDN

And the error I get:

vuetable: pagination-path "pagination" not found. It looks like the data returned from the sever does not have pagination information or you may have set it incorrectly. (anonymous) @ vue-table.min.js:1

ratiw commented 7 years ago

The transform function should return the transformed object. The example in the wiki is also missing this. Sorry for that.