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

store table data in variable #90

Closed z1haze closed 8 years ago

z1haze commented 8 years ago

I would like to know how to access the data for the table so I can use it and store it in a property. I would only like to display a specific element if results are present, and I think this would be beneficial. Thanks!

ratiw commented 8 years ago

@z1haze I don't understand what you would like to do. Please explain more.

z1haze commented 8 years ago

The data that is returned from the api-url and goes into the table, I would like to store that in a data variable. Unless I'm missing something, (which i probably am) i dont see how to grab the data from the table specifically. Thanks!

ratiw commented 8 years ago

@z1haze Use v-ref to reference your vuetable and access your data using tableData, like so:

  <vuetable v-ref="mytable"></vuetable>
  var vm = new Vue({....});

  console.log(vm.$refs.mytable.tableData[0])
z1haze commented 8 years ago

sweet, not a lot you haven't thought of!

z1haze commented 8 years ago

I finally got around to attempting this, but all i am getting is undefined for this. In the example in the wiki here you use v-ref:vuetable, trying to change that to v-ref="mytable" breaks t he site v-ref:undefined must be used on a child component. Found on <div>. (found in component: <server-votes>)

ratiw commented 8 years ago

@z1haze I may have given you the incorrect syntax, please check its documentation here

The given error is in your <server-votes> component. Advise you to carefully check it first.

dchao6 commented 7 years ago

For future reference, the correct syntax is:

<vuetable v-ref:mytable></vue-table>

And the data are accessible by:

var vm = new Vue({....});

console.log(vm.$refs.mytable.tableData[0])