2

Below is the sample response from an API. How can use I Vuetify Data Tables to render it.

Json:

{
    "records":[[101,"Aa"],[102,"Bb"],[103,"Cc"]],
    "column_names":["Id","Name"]
}

Table:

 Id  |  Name
- - - - - - -
 101 |  Aa
 102 |  Bb
 103 |  Cc

Key problem is that it don't have items as dictionary.

2 Answers 2

4

For basic Vuetify data table, you need to define headers and items as empty arrays.

data() {
  return {
    headers: [],
    items: []
  }
}

Then just fetch your "column_names" data to populate headers and "records" data to populate items
Something like:

response['column_names'].forEach(resp => {
  this.headers.push({ text: resp, value: resp.toLowerCase() })
})
response['records'].forEach(resp => {
  this.items.push({ id: resp[0], name: resp[1] })
})

Items keys just need to match with the headers values (in your example : "id" and "name")

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer. Is this efficient if I'm getting millions of records? Is there any way other way to implement without redecorating the data?
@bkmagnetron you can use pagination (codepen example) if you have a lot of records
@Sovalina is there a way to do this while maintaining reactivity to the source data?
0

for the html, map it to the item array by index?

<td>{{ props.item[0] }}</td>
<td>{{ props.item[1] }}</td>

the reason to use array of array is for performance, right? I dont think changing it to object is a proper solution.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.