Search code examples
vue.jsgraphqlbootstrap-vuegridsome

How to use GraphQL queries with BootstrapVue b-table?


I can use <b-table-simple> with GraphQL queries and it works fine, for example:

<b-table-simple>
      <b-tbody>
        <b-tr role="row" v-for="page in $page.allGoogleSheet.edges" :key="page.id">
          <b-td>
            {{page.node.Name}}
          </b-td>
          <b-td>
            {{page.node.Age}}
          </b-td>
          <b-td>
            {{page.node.Height}}
          </b-td>
        </b-tr>
      </b-tbody>
</b-table-simple>

But how can i do this with <b-table>?


Solution

  • You need to define your fields to pluck from each row of data:

    <template>
      <b-table :fields="fields" :items="$page.allGoogleSheet.edges">
      </b-table>
    </template>
    
    <script>
    export default {
      data() {
        return {
          fields: [
            // Add this entry if you want to see the ID of the entry
            // { key: 'id', label: 'ID' },
            { key: 'node.Name', label: 'Name' },
            { key: 'node.Age', label: 'Age' },
            { key: 'node.Height', label: 'Height' },
          ]
        }
      }
    }
    </script>