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 303 forks source link

vuetable can export out the data into excel or csv? #48

Closed lizhi2013 closed 8 years ago

lizhi2013 commented 8 years ago

vuetable can export out the data into excel or csv?

gurghet commented 8 years ago

What's the point if you already work with data in a json? There are already a lot of json to csv converters out there. http://konklone.io/json/

ratiw commented 8 years ago

@lizhi2013 Nope, it cannot. As @gurghet has suggested, I think there are other libraries that can do just that. :)

aaronbartell commented 7 years ago

I realize this is a closed issue, but I thought I'd comment on my solution so others can gain from it. It's likely you already have a JSON dataset in the local browser that you want to convert into a csv file that the browser will prompt the user to save. Below accomplishes that goal.

  methods: {
    csvExport: function (users) {
      var csvContent = "data:text/csv;charset=utf-8,";
      csvContent += this.users.map(function(d){
        console.log(d);
        return JSON.stringify(d);
      })
      .join('\n') 
      .replace(/(^\{)|(\}$)/mg, '');
      window.open( encodeURI(csvContent) );
    }
  }