Vue-tables-2: data.map is not a function on server-side with custom requestFunction

Created on 5 Oct 2017  路  3Comments  路  Source: matfish2/vue-tables-2

  • Vue.js version: 2.3.4
  • consumed using: webpack
  • FULL error message (including stack trace):
Uncaught (in promise) TypeError: data.map is not a function
    at VueComponent.module.exports (apply-filters.js?c856:4)
    at VueComponent.boundFn [as applyFilters] (vue.runtime.esm.js?ff9b:164)
    at VueComponent.module.exports (set-data.js?1d48:4)
    at VueComponent.boundFn [as setData] (vue.runtime.esm.js?ff9b:164)
    at VueComponent.eval (v-server-table.js?44f6:82)
    at <anonymous>
  • relevant code:
    Component:
<v-server-table url="/people"
                    :columns="columns"
                    :options="options">

Data table options:

options: {
        requestFunction: (data) => {
          let req = this.$auth.httpConfig();
          req.url = "/people";
          req.method = 'get';
          req.data = {
            params: data
          };
          return this.$http(req).catch(function(e) {
            //this.dispatch('error', e);
          });
        }
      }

Server response:
{"data":[{"first_name":"Ryan","last_name":"Chenkie","email":"[email protected]"},{"first_name":"Chris","last_name":"Sevilleja","email":"[email protected]"},{"first_name":"Holly","last_name":"Lloyd","email":"[email protected]"},{"first_name":"Adnan","last_name":"Kukic","email":"[email protected]"},{"first_name":"Leonel Adri\u00e1n","last_name":"Silva","email":null}],"count":5}

  • steps for reproducing the issue:

It seems that map function is called on the base object, it should be: data.data.map

Most helpful comment

Try the responseAdapter:

responseAdapter: function(resp) { 

var d = resp.data;

return { 
      data: d.data, 
      count: d.count 
   } 
}

All 3 comments

Try the responseAdapter:

responseAdapter: function(resp) { 

var d = resp.data;

return { 
      data: d.data, 
      count: d.count 
   } 
}

Thanks that worked!

Thanks a lot! This issue is also solved to me!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manrix picture manrix  路  3Comments

bb78657 picture bb78657  路  6Comments

molerat619 picture molerat619  路  4Comments

deryckoe picture deryckoe  路  3Comments

seivad picture seivad  路  3Comments