Skip to content

How enabled sorting without fields object #6562

Answered by Hiws
Eliophot asked this question in Q&A
Discussion options

You must be logged in to vote

I don't believe it's possible without passing in a fields array.

Assuming you're currently utilizing the auto generated fields by only passing in items.
You could utilize the same method to generate a fields array which you can then pass to your table.

<b-table :items="items" :fields="fields" />

{
  computed: {
    fields() {
      if(this.items.length === 0) return [];
      const item = this.items[0];
      return Object.keys(item).map(field => ({ key: field, sortable: true }));
    }
  },
  data() {
    return {
      items: []
    }
  }
}

The above example will generate a field array based on the first object in your items array.
It will then map the keys and add sortable: true to al…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Eliophot
Comment options

Answer selected by Hiws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants